From 2d12b53fdd65ef887d15ca7961d60341212ce1ec Mon Sep 17 00:00:00 2001 From: NotSqrt Date: Wed, 29 Oct 2014 19:52:01 +0100 Subject: [PATCH 01/11] Py3, django 1.7 for example app, wheel support, tox --- .gitignore | 1 + .../protected_downloads/download/tests.py | 16 --------- .../protected_downloads/example/__init__.py | 0 .../{ => example}/settings.py | 2 +- .../protected_downloads/{ => example}/urls.py | 0 examples/protected_downloads/manage.py | 16 ++++----- examples/protected_downloads/sendfile | 1 - sendfile/backends/_internalredirect.py | 4 ++- sendfile/backends/xsendfile.py | 2 +- sendfile/tests.py | 6 ++-- setup.cfg | 3 ++ setup.py | 18 +++++----- tox.ini | 36 +++++++++++++++++++ 13 files changed, 63 insertions(+), 42 deletions(-) delete mode 100644 examples/protected_downloads/download/tests.py create mode 100644 examples/protected_downloads/example/__init__.py rename examples/protected_downloads/{ => example}/settings.py (98%) rename examples/protected_downloads/{ => example}/urls.py (100%) delete mode 120000 examples/protected_downloads/sendfile create mode 100644 setup.cfg create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 2267b36..dbd3fb4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /lib /build .Python +.tox \ No newline at end of file diff --git a/examples/protected_downloads/download/tests.py b/examples/protected_downloads/download/tests.py deleted file mode 100644 index 501deb7..0000000 --- a/examples/protected_downloads/download/tests.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) diff --git a/examples/protected_downloads/example/__init__.py b/examples/protected_downloads/example/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/protected_downloads/settings.py b/examples/protected_downloads/example/settings.py similarity index 98% rename from examples/protected_downloads/settings.py rename to examples/protected_downloads/example/settings.py index 245739c..639a11e 100644 --- a/examples/protected_downloads/settings.py +++ b/examples/protected_downloads/example/settings.py @@ -67,7 +67,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', ) -ROOT_URLCONF = 'protected_downloads.urls' +ROOT_URLCONF = 'example.urls' TEMPLATE_DIRS = ( os.path.join(PROJECT_ROOT, 'templates'), diff --git a/examples/protected_downloads/urls.py b/examples/protected_downloads/example/urls.py similarity index 100% rename from examples/protected_downloads/urls.py rename to examples/protected_downloads/example/urls.py diff --git a/examples/protected_downloads/manage.py b/examples/protected_downloads/manage.py index 3e098b0..2605e37 100644 --- a/examples/protected_downloads/manage.py +++ b/examples/protected_downloads/manage.py @@ -1,14 +1,10 @@ #!/usr/bin/env python +import os +import sys -from __future__ import absolute_import +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") -from django.core.management import execute_manager -try: - from . import settings # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) - sys.exit(1) + from django.core.management import execute_from_command_line -if __name__ == "__main__": - execute_manager(settings) + execute_from_command_line(sys.argv) diff --git a/examples/protected_downloads/sendfile b/examples/protected_downloads/sendfile deleted file mode 120000 index fca7c70..0000000 --- a/examples/protected_downloads/sendfile +++ /dev/null @@ -1 +0,0 @@ -../../sendfile \ No newline at end of file diff --git a/sendfile/backends/_internalredirect.py b/sendfile/backends/_internalredirect.py index 65edd61..09511c0 100644 --- a/sendfile/backends/_internalredirect.py +++ b/sendfile/backends/_internalredirect.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf import settings from django.utils.http import urlquote import os.path @@ -12,4 +14,4 @@ def _convert_file_to_url(filename): relpath, head = os.path.split(relpath) url.insert(1, head) - return urlquote(u'/'.join(url)) + return urlquote('/'.join(url)) diff --git a/sendfile/backends/xsendfile.py b/sendfile/backends/xsendfile.py index 1f614ee..1df3057 100644 --- a/sendfile/backends/xsendfile.py +++ b/sendfile/backends/xsendfile.py @@ -4,6 +4,6 @@ def sendfile(request, filename, **kwargs): response = HttpResponse() - response['X-Sendfile'] = smart_str(unicode(filename)) + response['X-Sendfile'] = smart_str(filename) return response diff --git a/sendfile/tests.py b/sendfile/tests.py index 2e68e8b..79b11d9 100644 --- a/sendfile/tests.py +++ b/sendfile/tests.py @@ -1,5 +1,7 @@ # coding=utf-8 +from __future__ import unicode_literals + from django.conf import settings from django.test import TestCase from django.http import HttpResponse, Http404, HttpRequest @@ -102,7 +104,7 @@ def test_correct_file_in_xsendfile_header(self): self.assertEqual(filepath, response['X-Sendfile']) def test_xsendfile_header_containing_unicode(self): - filepath = self.ensure_file(u'péter_là_gueule.txt') + filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual(smart_str(filepath), response['X-Sendfile']) @@ -124,7 +126,7 @@ def test_correct_url_in_xaccelredirect_header(self): self.assertEqual('/private/readme.txt', response['X-Accel-Redirect']) def test_xaccelredirect_header_containing_unicode(self): - filepath = self.ensure_file(u'péter_là_gueule.txt') + filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual('/private/p%C3%A9ter_l%C3%A0_gueule.txt', response['X-Accel-Redirect']) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..412d336 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[wheel] +# create "py2.py3-none-any.whl" package +universal = 1 diff --git a/setup.py b/setup.py index 77d66be..db47819 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,4 @@ -from distutils.core import setup - -try: - from distutils.command.build_py import build_py_2to3 as build_py -except ImportError: - from distutils.command.build_py import build_py +from setuptools import setup version = __import__('sendfile').__version__ @@ -19,8 +14,8 @@ url='https://github.com/johnsensible/django-sendfile', license='BSD', - requires=['Django (>=1.3)', 'Unidecode'], - install_requires=['Django>=1.3', 'Unidecode'], + requires=['Django (>=1.4.2)', 'Unidecode'], + install_requires=['Django >=1.4.2', 'Unidecode'], packages=['sendfile', 'sendfile.backends'], package_dir={ @@ -40,8 +35,11 @@ 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', 'Topic :: Software Development :: Libraries :: Python Modules', ], - - cmdclass={'build_py': build_py}, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7018928 --- /dev/null +++ b/tox.ini @@ -0,0 +1,36 @@ +# Tox (http://codespeak.net/~hpk/tox/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +minversion=1.8.0 +envlist = + py26-django14, + py26-django15, + + py27-django14, + py27-django15, + py27-django16, + py27-django17, + + py32-django15, + py32-django16, + py32-django17, + + py33-django15, + py33-django16, + py33-django17, + + py34-django15, + py34-django16, + py34-django17, + +[testenv] +changedir = examples/protected_downloads +commands = python manage.py test sendfile +deps = + django14: django >=1.4.2,<1.5 + django15: django >=1.5,<1.6 + django16: django >=1.6,<1.7 + django17: django >=1.7,<1.8 From 31ceca3298c83b69361f7af59a65b06a0ca69506 Mon Sep 17 00:00:00 2001 From: NotSqrt Date: Wed, 29 Oct 2014 19:53:36 +0100 Subject: [PATCH 02/11] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dbd3fb4..55e9f48 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ /lib /build .Python -.tox \ No newline at end of file +.tox From 7d4ec9808a53b769124c701e12520f3ffe9bc9f1 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Wed, 5 Apr 2017 16:36:42 +0200 Subject: [PATCH 03/11] Compress test matrix and update with new Django versions --- tox.ini | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tox.ini b/tox.ini index 7018928..14aff66 100644 --- a/tox.ini +++ b/tox.ini @@ -4,27 +4,14 @@ # and then run "tox" from this directory. [tox] -minversion=1.8.0 +minversion = 2.2 envlist = - py26-django14, - py26-django15, - - py27-django14, - py27-django15, - py27-django16, - py27-django17, - - py32-django15, - py32-django16, - py32-django17, - - py33-django15, - py33-django16, - py33-django17, - - py34-django15, - py34-django16, - py34-django17, + py{26,27}-django14, + py{26,27,32,33}-django{15,16} + py{27,32,33,34}-django{17,18} + py{27,34,35}-django{19,110} + py{27,34,35,36}-django111 +skip_missing_interpreters = True [testenv] changedir = examples/protected_downloads @@ -34,3 +21,7 @@ deps = django15: django >=1.5,<1.6 django16: django >=1.6,<1.7 django17: django >=1.7,<1.8 + django18: django >=1.8,<1.9 + django19: django >=1.9,<1.10 + django110: django >=1.10,<1.11 + django111: django >=1.11,<2 From 2d9ef94189acb3c97db195723139ca0b733e9db2 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Wed, 5 Apr 2017 16:42:58 +0200 Subject: [PATCH 04/11] Add Travis CI integration --- .travis.yml | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0839ae7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,62 @@ +dist: trusty +sudo: false +language: python +cache: pip +matrix: + include: + - python: '2.6' + env: DJANGO=django14 + - python: '2.6' + env: DJANGO=django15 + - python: '2.6' + env: DJANGO=django16 + - python: '2.7' + env: DJANGO=django14 + - python: '2.7' + env: DJANGO=django15 + - python: '2.7' + env: DJANGO=django16 + - python: '2.7' + env: DJANGO=django17 + - python: '2.7' + env: DJANGO=django18 + - python: '2.7' + env: DJANGO=django19 + - python: '2.7' + env: DJANGO=django110 + - python: '2.7' + env: DJANGO=django111 + - python: '3.2' + env: DJANGO=django15 + - python: '3.2' + env: DJANGO=django16 + - python: '3.2' + env: DJANGO=django17 + - python: '3.2' + env: DJANGO=django18 + - python: '3.3' + env: DJANGO=django15 + - python: '3.3' + env: DJANGO=django16 + - python: '3.3' + env: DJANGO=django17 + - python: '3.3' + env: DJANGO=django18 + - python: '3.4' + env: DJANGO=django19 + - python: '3.4' + env: DJANGO=django110 + - python: '3.4' + env: DJANGO=django111 + - python: '3.5' + env: DJANGO=django19 + - python: '3.5' + env: DJANGO=django110 + - python: '3.5' + env: DJANGO=django111 + - python: '3.6' + env: DJANGO=django111 +install: + - pip install tox +script: + - tox -e py${TRAVIS_PYTHON_VERSION//.}-${DJANGO} -- -v 2 From b30328e815ddee346af671619ccf1cb9479d6367 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 10 Apr 2017 13:28:45 +0200 Subject: [PATCH 05/11] Reduce support to currently supported Django versions As declared upstream at https://www.djangoproject.com/download/#supported-versions Update Trove classifiers and requires/install_requires as a consequence. --- .travis.yml | 32 -------------------------------- setup.py | 10 +++++++--- tox.ini | 11 ++--------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0839ae7..641085a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,52 +4,20 @@ language: python cache: pip matrix: include: - - python: '2.6' - env: DJANGO=django14 - - python: '2.6' - env: DJANGO=django15 - - python: '2.6' - env: DJANGO=django16 - - python: '2.7' - env: DJANGO=django14 - - python: '2.7' - env: DJANGO=django15 - - python: '2.7' - env: DJANGO=django16 - - python: '2.7' - env: DJANGO=django17 - python: '2.7' env: DJANGO=django18 - - python: '2.7' - env: DJANGO=django19 - python: '2.7' env: DJANGO=django110 - python: '2.7' env: DJANGO=django111 - - python: '3.2' - env: DJANGO=django15 - - python: '3.2' - env: DJANGO=django16 - - python: '3.2' - env: DJANGO=django17 - python: '3.2' env: DJANGO=django18 - - python: '3.3' - env: DJANGO=django15 - - python: '3.3' - env: DJANGO=django16 - - python: '3.3' - env: DJANGO=django17 - python: '3.3' env: DJANGO=django18 - - python: '3.4' - env: DJANGO=django19 - python: '3.4' env: DJANGO=django110 - python: '3.4' env: DJANGO=django111 - - python: '3.5' - env: DJANGO=django19 - python: '3.5' env: DJANGO=django110 - python: '3.5' diff --git a/setup.py b/setup.py index 0e1eb71..37683d0 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,8 @@ url='https://github.com/johnsensible/django-sendfile', license='BSD', - requires=['Django (>=1.3)'], - install_requires=['Django>=1.3'], + requires=['Django (>=1.8)'], + install_requires=['Django>=1.8'], packages=['sendfile', 'sendfile.backends'], package_dir={ @@ -31,15 +31,19 @@ 'Development Status :: 4 - Beta', 'Environment :: Web Environment', 'Framework :: Django', + 'Framework :: Django :: 1.8', + 'Framework :: Django :: 1.10', + 'Framework :: Django :: 1.11', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Topic :: Software Development :: Libraries :: Python Modules', ], ) diff --git a/tox.ini b/tox.ini index 14aff66..cd6bfd8 100644 --- a/tox.ini +++ b/tox.ini @@ -6,10 +6,8 @@ [tox] minversion = 2.2 envlist = - py{26,27}-django14, - py{26,27,32,33}-django{15,16} - py{27,32,33,34}-django{17,18} - py{27,34,35}-django{19,110} + py{27,32,33,34}-django18 + py{27,34,35}-django110 py{27,34,35,36}-django111 skip_missing_interpreters = True @@ -17,11 +15,6 @@ skip_missing_interpreters = True changedir = examples/protected_downloads commands = python manage.py test sendfile deps = - django14: django >=1.4.2,<1.5 - django15: django >=1.5,<1.6 - django16: django >=1.6,<1.7 - django17: django >=1.7,<1.8 django18: django >=1.8,<1.9 - django19: django >=1.9,<1.10 django110: django >=1.10,<1.11 django111: django >=1.11,<2 From 20d8a2c1ff2e6ab6948baab0d85d60973d653dbc Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 13 Nov 2017 15:37:02 +0100 Subject: [PATCH 06/11] Fix declaration of applications URLs in unittests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make protected_download app known as download through the AppConfig mechanism. Inspired by Michał Pasternak commits in PR#66. --- examples/protected_downloads/download/apps.py | 5 +++++ examples/protected_downloads/download/urls.py | 6 +++--- examples/protected_downloads/example/urls.py | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 examples/protected_downloads/download/apps.py diff --git a/examples/protected_downloads/download/apps.py b/examples/protected_downloads/download/apps.py new file mode 100644 index 0000000..b340dce --- /dev/null +++ b/examples/protected_downloads/download/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DownloadAppConfig(AppConfig): + name = 'download' diff --git a/examples/protected_downloads/download/urls.py b/examples/protected_downloads/download/urls.py index fd4bb28..8188e4c 100644 --- a/examples/protected_downloads/download/urls.py +++ b/examples/protected_downloads/download/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls.defaults import * +from django.conf.urls import url from .views import download, download_list -urlpatterns = patterns('', +urlpatterns = [ url(r'^$', download_list), url(r'(?P\d+)/$', download, name='download'), -) +] diff --git a/examples/protected_downloads/example/urls.py b/examples/protected_downloads/example/urls.py index 238d8c7..80b96e1 100644 --- a/examples/protected_downloads/example/urls.py +++ b/examples/protected_downloads/example/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls.defaults import * +from django.conf.urls import url, include from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', - (r'^', include('protected_downloads.download.urls')), - (r'^admin/', include(admin.site.urls)), -) +urlpatterns = [ + url(r'^', include('download.urls')), + url(r'^admin/', include(admin.site.urls)), +] From b8d4ae153fb21152a60330ae15fa023641b8392f Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 13 Nov 2017 15:49:38 +0100 Subject: [PATCH 07/11] Fix encoding issue with python3 in sendfile function six dependency must be added to tox.ini as setup.py will just fail due to version importing code. Atomic commits from PR#66. --- sendfile/__init__.py | 8 ++++++-- setup.py | 2 +- tox.ini | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sendfile/__init__.py b/sendfile/__init__.py index 1cc9809..1f30983 100644 --- a/sendfile/__init__.py +++ b/sendfile/__init__.py @@ -5,6 +5,8 @@ from mimetypes import guess_type import unicodedata +import six + def _lazy_load(fn): _cached = [] @@ -77,8 +79,10 @@ def sendfile(request, filename, attachment=False, attachment_filename=None, mime # Django 1.3 from django.utils.encoding import force_unicode as force_text attachment_filename = force_text(attachment_filename) - ascii_filename = unicodedata.normalize('NFKD', attachment_filename).encode('ascii','ignore') - parts.append('filename="%s"' % ascii_filename) + ascii_filename = unicodedata.normalize('NFKD', attachment_filename).encode('ascii', 'ignore') + if six.PY3: + ascii_filename = ascii_filename.decode() + parts.append('filename="%s"' % str(ascii_filename)) if ascii_filename != attachment_filename: from django.utils.http import urlquote quoted_filename = urlquote(attachment_filename) diff --git a/setup.py b/setup.py index 37683d0..fb33b70 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ license='BSD', requires=['Django (>=1.8)'], - install_requires=['Django>=1.8'], + install_requires=['Django>=1.8', 'six'], packages=['sendfile', 'sendfile.backends'], package_dir={ diff --git a/tox.ini b/tox.ini index cd6bfd8..7ca720c 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ skip_missing_interpreters = True changedir = examples/protected_downloads commands = python manage.py test sendfile deps = + six django18: django >=1.8,<1.9 django110: django >=1.10,<1.11 django111: django >=1.11,<2 From bb610558460e586b2886815362e322e435a71b87 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 13 Nov 2017 16:19:10 +0100 Subject: [PATCH 08/11] Fix encoding issue with python3 in unittests Atomic commits from PR#66. --- sendfile/tests.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sendfile/tests.py b/sendfile/tests.py index edc088a..8a4db1e 100644 --- a/sendfile/tests.py +++ b/sendfile/tests.py @@ -10,6 +10,7 @@ from tempfile import mkdtemp import shutil from sendfile import sendfile as real_sendfile, _get_sendfile +import six try: from urllib.parse import unquote @@ -134,7 +135,10 @@ def test_xaccelredirect_header_containing_unicode(self): filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) - self.assertEqual(u'/private/péter_là_gueule.txt'.encode('utf-8'), unquote(response['X-Accel-Redirect'])) + path = '/private/péter_là_gueule.txt' + if six.PY2: + path = path.encode('utf-8') + self.assertEqual(path, unquote(response['X-Accel-Redirect'])) class TestModWsgiBackend(TempFileTestCase): @@ -156,4 +160,7 @@ def test_location_header_containing_unicode(self): filepath = self.ensure_file(u'péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) - self.assertEqual(u'/private/péter_là_gueule.txt'.encode('utf-8'), unquote(response['Location'])) + path = '/private/péter_là_gueule.txt' + if six.PY2: + path = path.encode('utf-8') + self.assertEqual(path, unquote(response['Location'])) From 727bb7c5cfbfd8aa341b947571833a09ceb4d2fb Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 13 Nov 2017 16:22:57 +0100 Subject: [PATCH 09/11] Fix encoding issue with python3 in xsendfile backend Atomic commits from PR#66. --- sendfile/backends/xsendfile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sendfile/backends/xsendfile.py b/sendfile/backends/xsendfile.py index a87aa83..3c603e1 100644 --- a/sendfile/backends/xsendfile.py +++ b/sendfile/backends/xsendfile.py @@ -1,8 +1,12 @@ from django.http import HttpResponse +import six def sendfile(request, filename, **kwargs): response = HttpResponse() - response['X-Sendfile'] = unicode(filename).encode('utf-8') + if six.PY2: + response['X-Sendfile'] = unicode(filename).encode('utf-8') + else: + response['X-Sendfile'] = filename return response From 45f6ffe537a54de86a38d8746b4e16a04e5b5b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Fri, 30 Jun 2017 13:42:27 +0200 Subject: [PATCH 10/11] Add Travis CI build badge Signed-off-by: Gilles Dartiguelongue --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 76ccf99..61a2451 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,9 @@ Django Sendfile =============== +.. image:: https://img.shields.io/travis/lexfo/django-sendfile.svg + :target: https://travis-ci.org/lexfo/django-sendfile + This is a wrapper around web-server specific methods for sending files to web clients. This is useful when Django needs to check permissions associated files, but does not want to serve the actual bytes of the file itself. i.e. as serving large files is not what Django is made for. Note this should not be used for regular file serving (e.g. css etc), only for cases where you need Django to do some work before serving the actual file. From 48b63199c351ea1ec66160636ee81af25176e51e Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 13 Nov 2017 16:48:47 +0100 Subject: [PATCH 11/11] Drop remaining unicode markers for python2 Since unicode_literals is imported, there is no need to have this explicit string marker. Also, it breaks with python3.2. --- sendfile/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendfile/tests.py b/sendfile/tests.py index 8a4db1e..02ad369 100644 --- a/sendfile/tests.py +++ b/sendfile/tests.py @@ -157,7 +157,7 @@ def test_correct_url_in_location_header(self): self.assertEqual('/private/readme.txt', response['Location']) def test_location_header_containing_unicode(self): - filepath = self.ensure_file(u'péter_là_gueule.txt') + filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) path = '/private/péter_là_gueule.txt'