kopia lustrzana https://github.com/wagtail/wagtail
Remove Python 2 fallback code
rodzic
70e342a38d
commit
4089811aed
|
@ -404,12 +404,6 @@ class Block(six.with_metaclass(BaseBlock, object)):
|
|||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
# Making block instances hashable in a way that's consistent with __eq__ is non-trivial, because
|
||||
# self.deconstruct() is liable to contain unhashable data (e.g. lists and dicts). So let's set
|
||||
# Block to be explicitly unhashable - Python 3 will do this automatically when defining __eq__,
|
||||
# but Python 2 won't, and we'd like the behaviour to be consistent on both.
|
||||
__hash__ = None
|
||||
|
||||
|
||||
class BoundBlock(object):
|
||||
def __init__(self, block, value, prefix=None, errors=None):
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import inspect
|
||||
import re
|
||||
import sys
|
||||
|
||||
# helpers for Javascript expression formatting
|
||||
|
||||
|
@ -24,20 +22,3 @@ def js_dict(d):
|
|||
for (k, v) in d.items()
|
||||
]
|
||||
return "{\n%s\n}" % ',\n'.join(dict_items)
|
||||
|
||||
|
||||
def accepts_kwarg(func, kwarg):
|
||||
"""
|
||||
Determine whether the callable `func` has a signature that accepts the keyword argument `kwarg`
|
||||
"""
|
||||
if sys.version_info >= (3, 3):
|
||||
signature = inspect.signature(func)
|
||||
try:
|
||||
signature.bind_partial(**{kwarg: None})
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
else:
|
||||
# Fall back on inspect.getargspec, available on Python 2.7 but deprecated since 3.5
|
||||
argspec = inspect.getargspec(func)
|
||||
return (kwarg in argspec.args) or (argspec.keywords is not None)
|
||||
|
|
|
@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import inspect
|
||||
import re
|
||||
import sys
|
||||
import unicodedata
|
||||
|
||||
from django.apps import apps
|
||||
|
@ -102,14 +101,9 @@ def accepts_kwarg(func, kwarg):
|
|||
"""
|
||||
Determine whether the callable `func` has a signature that accepts the keyword argument `kwarg`
|
||||
"""
|
||||
if sys.version_info >= (3, 3):
|
||||
signature = inspect.signature(func)
|
||||
try:
|
||||
signature.bind_partial(**{kwarg: None})
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
else:
|
||||
# Fall back on inspect.getargspec, available on Python 2.7 but deprecated since 3.5
|
||||
argspec = inspect.getargspec(func)
|
||||
return (kwarg in argspec.args) or (argspec.keywords is not None)
|
||||
signature = inspect.signature(func)
|
||||
try:
|
||||
signature.bind_partial(**{kwarg: None})
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
|
|
|
@ -187,8 +187,6 @@ class TestServeWithUnicodeFilename(TestCase):
|
|||
def setUp(self):
|
||||
self.document = models.Document(title="Test document")
|
||||
|
||||
# Setting this filename in the content-disposition header fails on Django <1.8, Python 2
|
||||
# due to https://code.djangoproject.com/ticket/20889
|
||||
self.filename = 'docs\u0627\u0644\u0643\u0627\u062a\u062f\u0631\u0627'
|
||||
'\u064a\u064a\u0629_\u0648\u0627\u0644\u0633\u0648\u0642'
|
||||
try:
|
||||
|
|
|
@ -4,10 +4,9 @@ from wsgiref.util import FileWrapper
|
|||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import BadHeaderError, Http404, HttpResponse, StreamingHttpResponse
|
||||
from django.http import Http404, HttpResponse, StreamingHttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from unidecode import unidecode
|
||||
|
||||
from wagtail.utils import sendfile_streaming_backend
|
||||
from wagtail.utils.sendfile import sendfile
|
||||
|
@ -67,12 +66,7 @@ def serve(request, document_id, document_filename):
|
|||
wrapper = FileWrapper(doc.file)
|
||||
response = StreamingHttpResponse(wrapper, content_type='application/octet-stream')
|
||||
|
||||
try:
|
||||
response['Content-Disposition'] = 'attachment; filename=%s' % doc.filename
|
||||
except BadHeaderError:
|
||||
# Unicode filenames can fail on Django <1.8, Python 2 due to
|
||||
# https://code.djangoproject.com/ticket/20889 - try with an ASCIIfied version of the name
|
||||
response['Content-Disposition'] = 'attachment; filename=%s' % unidecode(doc.filename)
|
||||
response['Content-Disposition'] = 'attachment; filename=%s' % doc.filename
|
||||
|
||||
# FIXME: storage backends are not guaranteed to implement 'size'
|
||||
response['Content-Length'] = doc.file.size
|
||||
|
|
Ładowanie…
Reference in New Issue