summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/datastructures.py2
-rw-r--r--django/utils/dateformat.py2
-rw-r--r--django/utils/feedgenerator.py6
-rw-r--r--django/utils/text.py18
4 files changed, 24 insertions, 4 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 3d7c4275bb..632e804f26 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -1,4 +1,4 @@
-class MergeDict:
+class MergeDict(object):
"""
A simple class for creating new "virtual" dictionaries that actualy look
up values in more than one dictionary, passed in the constructor.
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 4e5f2bc8c0..0890a81a81 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -19,7 +19,7 @@ import re, time
re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
re_escaped = re.compile(r'\\(.)')
-class Formatter:
+class Formatter(object):
def format(self, formatstr):
pieces = []
for i, piece in enumerate(re_formatchars.split(formatstr)):
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 4c5d515f41..2eb27a40b7 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -36,7 +36,7 @@ def get_tag_uri(url, date):
tag = re.sub('#', '/', tag)
return 'tag:' + tag
-class SyndicationFeed:
+class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()"
def __init__(self, title, link, description, language=None, author_email=None,
author_name=None, author_link=None, subtitle=None, categories=None,
@@ -108,7 +108,7 @@ class SyndicationFeed:
else:
return datetime.datetime.now()
-class Enclosure:
+class Enclosure(object):
"Represents an RSS enclosure"
def __init__(self, url, length, mime_type):
"All args are expected to be Python Unicode objects"
@@ -126,6 +126,8 @@ class RssFeed(SyndicationFeed):
handler.addQuickElement(u"description", self.feed['description'])
if self.feed['language'] is not None:
handler.addQuickElement(u"language", self.feed['language'])
+ for cat in self.feed['categories']:
+ handler.addQuickElement(u"category", cat)
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
diff --git a/django/utils/text.py b/django/utils/text.py
index 7b6e1182ab..7df9bc03b7 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -109,3 +109,21 @@ def javascript_quote(s):
s = s.replace("'", "\\'")
return str(ustring_re.sub(fix, s))
+smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
+def smart_split(text):
+ """
+ Generator that splits a string by spaces, leaving quoted phrases together.
+ Supports both single and double quotes, and supports escaping quotes with
+ backslashes. In the output, strings will keep their initial and trailing
+ quote marks.
+ >>> list(smart_split('This is "a person\'s" test.'))
+ ['This', 'is', '"a person\'s"', 'test.']
+ """
+ for bit in smart_split_re.finditer(text):
+ bit = bit.group(0)
+ if bit[0] == '"':
+ yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"'
+ elif bit[0] == "'":
+ yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'"
+ else:
+ yield bit