decorator () получил неожиданный аргумент ключевого слова 'trim_url_limit' - PullRequest
0 голосов
/ 26 октября 2019

enter image description here decorator () получил неожиданный аргумент ключевого слова 'trim_url_limit'

Ошибка в urlfiltertrunc, строка 183

"return mark_safe (django_165_urlize_impl (значение, trim_url_limit)= int (limit), nofollow = True, autoescape = autoescape)) "

Этот код работал, когда я был ниже 1.9, но когда я недавно перешел на django 2.2, он начал выдавать эту ошибку. Кажется, что-то сделать, что изменение в версии Django.

Ниже приведен подробный код.

URL.py

def django_165_urlize_impl(text, trim_url_limit=None, nofollow=False, autoescape=False, newtab=True):
"""
Implementation is from Django 1.6.5 -- modified to add target='blank_'
Converts any URLs in text into clickable links.
Works on http://, https://, www. links, and also on links ending in one of
the original seven gTLDs (.com, .edu, .gov, .int, .mil, .net, and .org).
Links can have trailing punctuation (periods, commas, close-parens) and
leading punctuation (opening parens) and it'll still do the right thing.

If trim_url_limit is not None, the URLs in link text longer than this limit
will truncated to trim_url_limit-3 characters and appended with an elipsis.

If nofollow is True, the URLs in link text will get a rel="nofollow"
attribute.
If autoescape is True, the link text and URLs will get autoescaped.
"""

safe_input = isinstance(text, SafeData)

def trim_url(x, limit=trim_url_limit):
    if limit is None or len(x) <= limit:
        return x
    return '%s...' % x[:max(0, limit - 3)]

words = word_split_re.split(force_text(text))

for i, word in enumerate(words):
    match = None
    if '.' in word or '@' in word or ':' in word:

        # Deal with punctuation.
        lead, middle, trail = '', word, ''
        for punctuation in TRAILING_PUNCTUATION:
            if middle.endswith(punctuation):
                middle = middle[:-len(punctuation)]
                trail = punctuation + trail

        for opening, closing in WRAPPING_PUNCTUATION:
            if middle.startswith(opening):
                middle = middle[len(opening):]
                lead = lead + opening

            # Keep parentheses at the end only if they're balanced.
            if (middle.endswith(closing)
                and middle.count(closing) == middle.count(opening) + 1):
                middle = middle[:-len(closing)]
                trail = closing + trail

        # Make URL we want to point to.
        url = None
        nofollow_attr = ' rel="nofollow"' if nofollow else ''
        if simple_url_re.match(middle):
            url = smart_urlquote(middle)
        elif simple_url_2_re.match(middle):
            url = smart_urlquote('http://%s' % middle)
        elif not ':' in middle and simple_email_re.match(middle):
            local, domain = middle.rsplit('@', 1)
            try:
                domain = domain.encode('idna').decode('ascii')
            except UnicodeError:
                continue
            url = 'mailto:%s@%s' % (local, domain)
            nofollow_attr = ''

        # Make link.
        if url:
            trimmed = trim_url(middle)
            if autoescape and not safe_input:
                lead, trail = escape(lead), escape(trail)
                url, trimmed = escape(url), escape(trimmed)
            middle = '<a href="%s"%s>%s</a>' % (url, nofollow_attr, trimmed)
            if newtab:
                middle = '<a target="blank_" href="%s"%s>%s</a>' % (url, nofollow_attr, trimmed)
            words[i] = mark_safe('%s%s%s' % (lead, middle, trail))
        else:
            if safe_input:
                words[i] = mark_safe(word)
            elif autoescape:
                words[i] = escape(word)
    elif safe_input:
        words[i] = mark_safe(word)
    elif autoescape:
        words[i] = escape(word)
return ''.join(words)

django_165_urlize_impl = allow_lazy(django_165_urlize_impl, six.text_type)

@register.filter(is_safe=True, needs_autoescape=True)
@stringfilter
def urlfilter(value, autoescape=None):
"""Converts URLs in plain text into clickable links."""
return mark_safe(django_165_urlize_impl(value, nofollow=True, autoescape=autoescape))

@register.filter(is_safe=True, needs_autoescape=True)
@stringfilter
def urlfiltertrunc(value, limit, autoescape=None):
"""
Converts URLs into clickable links, truncating URLs to the given character
limit, and adding 'rel=nofollow' attribute to discourage spamming.

Argument: Length to truncate URLs to.
"""
print(limit)
print(value)
print(autoescape)
return mark_safe(django_165_urlize_impl(value, trim_url_limit=int(limit), nofollow=True, autoescape=autoescape))
...