Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Fantomas42/django-blog-zinnia
base: 3516e9529a
...
head fork: Fantomas42/django-blog-zinnia
compare: 1c8e0b9e28
  • 6 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
View
1  setup.py
@@ -25,6 +25,7 @@
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Programming Language :: Python',
+ 'Programming Language :: Python :: 3',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'License :: OSI Approved :: BSD License',
View
4 zinnia/comparison.py
@@ -1,5 +1,7 @@
"""Comparison tools for Zinnia
Based on clustered_models app"""
+from django.utils import six
+
from math import sqrt
from zinnia.settings import F_MIN
@@ -36,7 +38,7 @@ def dataset(self):
and specified fields"""
dataset = {}
for item in self.queryset.filter():
- dataset[item] = ' '.join([unicode(getattr(item, field))
+ dataset[item] = ' '.join([six.text_type(getattr(item, field))
for field in self.fields])
return dataset
View
6 zinnia/feeds.py
@@ -1,5 +1,9 @@
"""Feeds for Zinnia"""
-from urlparse import urljoin
+try:
+ from urllib.parse import urljoin
+except ImportError: # Python 2
+ from urlparse import urljoin
+
from BeautifulSoup import BeautifulSoup
from django.contrib import comments
View
7 zinnia/management/commands/blogger2zinnia.py
@@ -7,6 +7,7 @@
from django.conf import settings
from django.utils import timezone
+from django.utils.six.moves import input
from django.utils.encoding import smart_str
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify
@@ -80,7 +81,7 @@ def handle_noargs(self, **options):
'Starting migration from Blogger to Zinnia %s\n' % __version__))
if not self.blogger_username:
- self.blogger_username = raw_input('Blogger username: ')
+ self.blogger_username = input('Blogger username: ')
if not self.blogger_username:
raise CommandError('Invalid Blogger username')
@@ -107,7 +108,7 @@ def handle_noargs(self, **options):
self.select_blog_id()
if not self.category_title:
- self.category_title = raw_input(
+ self.category_title = input(
'Category title for imported entries: ')
if not self.category_title:
raise CommandError('Invalid category title')
@@ -126,7 +127,7 @@ def select_blog_id(self):
self.write_out('%s. %s (%s)' % (i, blog.title.text,
get_blog_id(blog)))
try:
- blog_index = int(raw_input('\nSelect a blog to import: '))
+ blog_index = int(input('\nSelect a blog to import: '))
blog = blogs[blog_index]
break
except (ValueError, KeyError):
View
5 zinnia/management/commands/feed2zinnia.py
@@ -1,9 +1,12 @@
"""Feed to Zinnia command module"""
import os
import sys
-from urllib2 import urlopen
from datetime import datetime
from optparse import make_option
+try:
+ from urllib.request import urlopen
+except ImportError: # Python 2
+ from urllib2 import urlopen
from django.conf import settings
from django.utils import timezone
View
2  zinnia/management/commands/spam_cleanup.py
@@ -24,4 +24,4 @@ def handle_noargs(self, **options):
spams.delete()
if verbosity:
- print '%i spam comments deleted.' % spams_count
+ print('%i spam comments deleted.' % spams_count)
View
12 zinnia/management/commands/wp2zinnia.py
@@ -1,16 +1,20 @@
"""WordPress to Zinnia command module"""
import os
import sys
-from urllib2 import urlopen
from datetime import datetime
from optparse import make_option
from xml.etree import ElementTree as ET
+try:
+ from urllib.request import urlopen
+except ImportError: # Python 2
+ from urllib2 import urlopen
from django.conf import settings
from django.utils import timezone
from django.core.files import File
from django.utils.text import Truncator
from django.utils.html import strip_tags
+from django.utils.six.moves import input
from django.db.utils import IntegrityError
from django.utils.encoding import smart_str
from django.contrib.sites.models import Site
@@ -143,7 +147,7 @@ def migrate_author(self, author_name):
"2. Create a new user ?\n"\
"Please select a choice: " % self.style.ITEM(author_name)
while 42:
- selection = raw_input(smart_str(action_text))
+ selection = input(smart_str(action_text))
if selection and selection in '12':
break
if selection == '1':
@@ -171,7 +175,7 @@ def migrate_author(self, author_name):
"%s or 'back'\n"\
"Please select a choice: " % \
', '.join(usernames_display)
- user_selected = raw_input(user_text)
+ user_selected = input(user_text)
if user_selected in usernames:
break
if user_selected == '' and preselected_user:
@@ -183,7 +187,7 @@ def migrate_author(self, author_name):
else:
create_text = "2. Please type the email of " \
"the '%s' user or 'back': " % author_name
- author_mail = raw_input(create_text)
+ author_mail = input(create_text)
if author_mail.strip() == 'back':
return self.migrate_author(author_name)
try:
View
2  zinnia/management/commands/zinnia2wp.py
@@ -28,4 +28,4 @@ def handle_noargs(self, **options):
'site': site,
'site_url': '%s://%s' % (PROTOCOL, site.domain)}
export = render_to_string('zinnia/wxr.xml', blog_context)
- print smart_str(export)
+ print(smart_str(export))
View
19 zinnia/ping.py
@@ -1,10 +1,17 @@
"""Pings utilities for Zinnia"""
import socket
-import xmlrpclib
import threading
-from urllib2 import urlopen
-from urlparse import urlsplit
from logging import getLogger
+try:
+ from urllib.request import urlopen
+ from urllib.parse import urlsplit
+ from xmlrpc.client import Error
+ from xmlrpc.client import ServerProxy
+except ImportError: # Python 2
+ from urllib2 import urlopen
+ from urlparse import urlsplit
+ from xmlrpclib import Error
+ from xmlrpclib import ServerProxy
from BeautifulSoup import BeautifulSoup
@@ -35,7 +42,7 @@ def __init__(self, server_name, entries, timeout=10, start_now=True):
self.timeout = timeout
self.entries = entries
self.server_name = server_name
- self.server = xmlrpclib.ServerProxy(self.server_name)
+ self.server = ServerProxy(self.server_name)
self.ressources = URLRessources()
threading.Thread.__init__(self)
@@ -161,8 +168,8 @@ def find_pingback_urls(self, urls):
def pingback_url(self, server_name, target_url):
"""Do a pingback call for the target url"""
try:
- server = xmlrpclib.ServerProxy(server_name)
+ server = ServerProxy(server_name)
reply = server.pingback.ping(self.entry_url, target_url)
- except (xmlrpclib.Error, socket.error):
+ except (Error, socket.error):
reply = '%s cannot be pinged.' % target_url
return reply
View
4 zinnia/search.py
@@ -1,4 +1,6 @@
"""Search module with complex query parsing for Zinnia"""
+from django.utils import six
+
from pyparsing import Word
from pyparsing import alphas
from pyparsing import WordEnd
@@ -26,7 +28,7 @@ def createQ(token):
query = getattr(token, 'query', '')
wildcards = None
- if isinstance(query, basestring): # Unicode -> Quoted string
+ if isinstance(query, six.string_types): # Unicode -> Quoted string
search = query
else: # List -> No quoted string (possible wildcards)
if len(query) == 1:
View
2  zinnia/spam_checker/__init__.py
@@ -16,7 +16,7 @@ def get_spam_checker(backend_path):
warnings.warn('%s backend cannot be imported' % backend_path,
RuntimeWarning)
backend = None
- except ImproperlyConfigured, e:
+ except ImproperlyConfigured as e:
warnings.warn(str(e), RuntimeWarning)
backend = None
View
8 zinnia/templatetags/zinnia_tags.py
@@ -1,7 +1,10 @@
"""Template tags and filters for Zinnia"""
from hashlib import md5
-from urllib import urlencode
from datetime import datetime
+try:
+ from urllib.parse import urlencode
+except ImportError: # Python 2
+ from urllib import urlencode
from django.db.models import Q
from django.db.models import Count
@@ -130,7 +133,8 @@ def compute_related(object_id, dataset):
if score:
entry_related[entry] = score
- related = sorted(entry_related.items(), key=lambda(k, v): (v, k))
+ related = sorted(entry_related.items(),
+ key=lambda k_v: (k_v[1], k_v[0]))
return [rel[0] for rel in related]
object_id = context['object'].pk
View
5 zinnia/tests/feeds.py
@@ -1,5 +1,8 @@
"""Test cases for Zinnia's feeds"""
-from urlparse import urljoin
+try:
+ from urllib.parse import urljoin
+except ImportError: # Python 2
+ from urlparse import urljoin
from django.test import TestCase
from django.contrib import comments
View
11 zinnia/tests/metaweblog.py
@@ -1,7 +1,12 @@
"""Test cases for Zinnia's MetaWeblog API"""
-from xmlrpclib import Binary
-from xmlrpclib import Fault
-from xmlrpclib import ServerProxy
+try:
+ from xmlrpc.client import Binary
+ from xmlrpc.client import Fault
+ from xmlrpc.client import ServerProxy
+except ImportError: # Python 2
+ from xmlrpclib import Binary
+ from xmlrpclib import Fault
+ from xmlrpclib import ServerProxy
from tempfile import TemporaryFile
from django.test import TestCase
View
15 zinnia/tests/ping.py
@@ -1,7 +1,12 @@
"""Test cases for Zinnia's ping"""
-import cStringIO
-from urllib2 import URLError
from urllib import addinfourl
+try:
+ from io import StringIO
+ from urllib.error import URLError
+except ImportError: # Python 2
+ from cStringIO import StringIO
+ from urllib2 import URLError
+
from django.test import TestCase
from zinnia.models.entry import Entry
@@ -89,15 +94,15 @@ def test_find_pingback_href(self):
def fake_urlopen(self, url):
"""Fake urlopen using test client"""
if 'example' in url:
- response = cStringIO.StringIO('')
+ response = StringIO('')
return addinfourl(response, {'X-Pingback': '/xmlrpc.php',
'Content-Type': 'text/html'}, url)
elif 'localhost' in url:
- response = cStringIO.StringIO(
+ response = StringIO(
'<link rel="pingback" href="/xmlrpc/">')
return addinfourl(response, {'Content-Type': 'text/xhtml'}, url)
elif 'google' in url:
- response = cStringIO.StringIO('PNG CONTENT')
+ response = StringIO('PNG CONTENT')
return addinfourl(response, {'content-type': 'image/png'}, url)
elif 'error' in url:
raise URLError('Invalid ressource')
View
16 zinnia/tests/pingback.py
@@ -1,8 +1,14 @@
"""Test cases for Zinnia's PingBack API"""
-import cStringIO
-from urlparse import urlsplit
-from urllib2 import HTTPError
-from xmlrpclib import ServerProxy
+try:
+ from io import StringIO
+ from urllib.error import HTTPError
+ from urllib.parse import urlsplit
+ from xmlrpc.client import ServerProxy
+except ImportError: # Python 2
+ from cStringIO import StringIO
+ from urllib2 import HTTPError
+ from urlparse import urlsplit
+ from xmlrpclib import ServerProxy
from django.test import TestCase
from django.contrib import comments
@@ -39,7 +45,7 @@ def fake_urlopen(self, url):
if not netloc:
raise
if self.site.domain == netloc:
- response = cStringIO.StringIO(self.client.get(url).content)
+ response = StringIO(self.client.get(url).content)
return response
raise HTTPError(url, 404, 'unavailable url', {}, None)
View
10 zinnia/tests/utils.py
@@ -1,6 +1,10 @@
"""Utils for Zinnia's tests"""
-import StringIO
-from xmlrpclib import Transport
+try:
+ from io import StringIO
+ from xmlrpc.client import Transport
+except ImportError: # Python 2
+ from StringIO import StringIO
+ from xmlrpclib import Transport
from datetime import datetime as original_datetime
from django.conf import settings
@@ -21,7 +25,7 @@ def request(self, host, handler, request_body, verbose=0):
response = self.client.post(handler,
request_body,
content_type="text/xml")
- res = StringIO.StringIO(response.content)
+ res = StringIO(response.content)
setattr(res, 'getheader', lambda *args: '') # For Python >= 2.7
res.seek(0)
if not hasattr(res, 'getheader'):
View
2  zinnia/url_shortener/__init__.py
@@ -17,7 +17,7 @@ def get_url_shortener():
warnings.warn('%s backend cannot be imported' % URL_SHORTENER_BACKEND,
RuntimeWarning)
backend = default_backend
- except ImproperlyConfigured, e:
+ except ImproperlyConfigured as e:
warnings.warn(str(e), RuntimeWarning)
backend = default_backend
View
5 zinnia/views/quick_entry.py
@@ -1,5 +1,8 @@
"""Views for Zinnia quick entry"""
-from urllib import urlencode
+try:
+ from urllib.parse import urlencode
+except: # Python 2
+ from urllib import urlencode
from django import forms
from django.shortcuts import redirect
View
13 zinnia/xmlrpc/metaweblog.py
@@ -1,9 +1,14 @@
"""XML-RPC methods of Zinnia metaWeblog API"""
import os
from datetime import datetime
-from xmlrpclib import Fault
-from xmlrpclib import DateTime
-
+try:
+ from xmlrpc.client import Fault
+ from xmlrpc.client import DateTime
+except ImportError: # Python 2
+ from xmlrpclib import Fault
+ from xmlrpclib import DateTime
+
+from django.utils import six
from django.conf import settings
from django.utils import timezone
from django.contrib.sites.models import Site
@@ -93,7 +98,7 @@ def post_structure(entry, site):
"""A post structure with extensions"""
author = entry.authors.all()[0]
return {'title': entry.title,
- 'description': unicode(entry.html_content),
+ 'description': six.text_type(entry.html_content),
'link': '%s://%s%s' % (PROTOCOL, site.domain,
entry.get_absolute_url()),
# Basic Extensions
View
19 zinnia/xmlrpc/pingback.py
@@ -1,9 +1,16 @@
"""XML-RPC methods of Zinnia Pingback"""
-from urllib2 import urlopen
-from urllib2 import URLError
-from urllib2 import HTTPError
-from urlparse import urlsplit
-
+try:
+ from urllib.error import URLError
+ from urllib.error import HTTPError
+ from urllib.request import urlopen
+ from urllib.parse import urlsplit
+except ImportError: # Python 2
+ from urllib2 import urlopen
+ from urllib2 import URLError
+ from urllib2 import HTTPError
+ from urlparse import urlsplit
+
+from django.utils import six
from django.contrib import comments
from django.utils.html import strip_tags
from django.contrib.sites.models import Site
@@ -33,7 +40,7 @@ def generate_pingback_content(soup, target, max_length, trunc_char='...'):
"""Generate a description text for the pingback"""
link = soup.find('a', href=target)
- content = strip_tags(unicode(link.findParent()))
+ content = strip_tags(six.text_type(link.findParent()))
index = content.index(link.string)
if len(content) > max_length:

No commit comments for this range

Something went wrong with that request. Please try again.