Skip to content

Commit

Permalink
Add support for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bfirsh committed Dec 15, 2016
1 parent 40cb3e6 commit fbaf3ec
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Expand Up @@ -2,14 +2,17 @@ language: python
sudo: false
python:
- "2.7"
- "3.4"
- "3.5"

env:
- DJANGO="Django>=1.7,<1.8"
- DJANGO="Django>=1.8,<1.9"
- DJANGO="Django>=1.9,<1.10"
- DJANGO="Django>=1.10,<1.11"

install: pip install $DJANGO --use-mirrors
install:
- python setup.py install
- pip install $DJANGO

script: script/test

2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -18,7 +18,7 @@ def read(fname):
packages = find_packages('src'),
package_dir = {'': 'src'},

install_requires = ['setuptools'],
install_requires = ['setuptools', 'six'],

classifiers = [
'Development Status :: 5 - Production/Stable',
Expand Down
2 changes: 1 addition & 1 deletion src/shorturls/__init__.py
Expand Up @@ -12,7 +12,7 @@
mod_name, conv_name = settings.SHORTURLS_DEFAULT_CONVERTER.rsplit('.', 1)
try:
mod = import_module(mod_name)
except ImportError, e:
except ImportError as e:
raise ImproperlyConfigured(
'Could not load converter specified by SHORTURLS_DEFAULT_CONVERTER. Error was: {0!s}'.format(e))
try:
Expand Down
5 changes: 3 additions & 2 deletions src/shorturls/templatetags/shorturl.py
@@ -1,4 +1,5 @@
import urlparse
from six.moves.urllib.parse import urljoin

from django import template
from django.conf import settings
from django.core import urlresolvers
Expand Down Expand Up @@ -33,7 +34,7 @@ def render(self, context):
tinyid = converter.from_decimal(obj.pk)

if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL:
return urlparse.urljoin(settings.SHORT_BASE_URL, prefix + tinyid)
return urljoin(settings.SHORT_BASE_URL, prefix + tinyid)

try:
return urlresolvers.reverse(views.redirect, kwargs={
Expand Down
2 changes: 1 addition & 1 deletion src/shorturls/tests/test_baseconv.py
Expand Up @@ -5,7 +5,7 @@
class BaseConvTests(unittest.TestCase):

def _test_converter(self, converter):
nums = [-10 ** 10, 10 ** 10] + range(-100, 100)
nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100))
for before in nums:
after = converter.to_decimal(converter.from_decimal(before))
self.assertEqual(before, after)
Expand Down
7 changes: 4 additions & 3 deletions src/shorturls/views.py
@@ -1,4 +1,5 @@
import urlparse
from six.moves.urllib.parse import urljoin, urlsplit

from django.apps import apps
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
Expand Down Expand Up @@ -43,7 +44,7 @@ def redirect(request, prefix, tiny, converter=default_converter):
# actually returns a domain-relative URL -- into a fully qualified one.

# If we got a fully-qualified URL, sweet.
if urlparse.urlsplit(url)[0]:
if urlsplit(url)[0]:
return HttpResponsePermanentRedirect(url)

# Otherwise, we need to make a full URL by prepending a base URL.
Expand All @@ -55,4 +56,4 @@ def redirect(request, prefix, tiny, converter=default_converter):
else:
base = 'http://{0!s}/'.format(get_current_site(request).domain)

return HttpResponsePermanentRedirect(urlparse.urljoin(base, url))
return HttpResponsePermanentRedirect(urljoin(base, url))

0 comments on commit fbaf3ec

Please sign in to comment.