Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mgaitan / waliki / 357

7 Aug 2017 - 8:18 coverage: 74.969% (-0.03%) from 75.0%
357

Pull #147

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Consistent handling of executable paths for external tools.
Pull Request #147: Consistent handling of executable paths for external tools.

8 of 10 new or added lines in 4 files covered. (80.0%)

2 existing lines in 1 file now uncovered.

1216 of 1622 relevant lines covered (74.97%)

6.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.68
/waliki/utils.py
1
import os
9×
2
import re
9×
3
import mimetypes
9×
4
import unicodedata
9×
5
from django.http import HttpResponse
9×
6
from django.core.urlresolvers import reverse
9×
7
from django.utils.six import PY2
9×
8
from django.utils.encoding import force_text
9×
9
from django.utils.safestring import mark_safe
9×
10

11
def get_slug(text):
9×
12
    def slugify(value):
9×
13
        """
14
        same than django slugify but allowing uppercase and underscore
15
        """
16
        value = force_text(value)
9×
17
        value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
9×
18
        value = re.sub('[^\w\s\/_-]', '', value).strip()
9×
19
        return mark_safe(re.sub('[-\s]+', '-', value))
9×
20

21
    if PY2:
9×
UNCOV
22
        from django.utils.encoding import force_unicode
!
UNCOV
23
        text = force_unicode(text)
!
24
    for sep in ('_', '/'):
9×
25
        text = sep.join(slugify(t) for t in text.split(sep))
9×
26
    return text.strip('/')
9×
27

28

29
def sanitize(html):
9×
30
    return re.sub(r'<script.*?</script>', '', html, flags=re.MULTILINE)
9×
31

32

33
def get_url(text, *args):
9×
34
    # *args needed to receive prefix and suffix for markdowns wikilinks ext
35
    from waliki.settings import get_slug
9×
36
    slug = get_slug(text)
9×
37
    if slug:
9×
38
        return reverse('waliki_detail', args=(get_slug(text),))
9×
39
    return ''
9×
40

41

42
def send_file(path, filename=None, content_type=None):
9×
43
    # TODO : remove it and use django-sendfile instead
44
    if filename is None:
!
45
        filename = os.path.basename(path)
!
46
    if content_type is None:
!
47
        content_type, encoding = mimetypes.guess_type(filename)
!
48
    response = HttpResponse(content_type=content_type)
!
49
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
!
50
    response.write(open(path, "rb").read())
!
51
    return response
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc