Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use xrange from six

  • Loading branch information...
commit 78e9f3dd0591f96b495f9d39f5fc11ae934f2f02 1 parent 45dbcc2
@graingert authored
Showing with 21 additions and 10 deletions.
  1. +4 −2 requirements.txt
  2. +4 −0 setup.py
  3. +13 −8 templatetag_sugar/parser.py
View
6 requirements.txt
@@ -1,4 +1,6 @@
-# Tests
-mock>=0.8.0
+# Install
Django>=1.3
+six
+
+# Tests
django-nose
View
4 setup.py
@@ -12,6 +12,10 @@
packages = [
"templatetag_sugar",
],
+ install_requires = [
+ "Django>=1.3",
+ "six",
+ ],
test_suite="runtests.runtests",
classifiers = [
"Development Status :: 3 - Alpha",
View
21 templatetag_sugar/parser.py
@@ -6,14 +6,16 @@
from templatetag_sugar.node import SugarNode
+from six.moves import xrange
+
class Parser(object):
def __init__(self, syntax, function):
self.syntax = syntax
self.function = function
-
+
def __call__(self, parser, token):
- # we're going to be doing pop(0) a bit, so a deque is way more
+ # we're going to be doing pop(0) a bit, so a deque is way more
# efficient
bits = deque(token.split_contents())
# pop the name of the tag off
@@ -42,22 +44,24 @@ class Parsable(object):
def resolve(self, context, value):
return value
+
class NamedParsable(Parsable):
def __init__(self, name=None):
self.name = name
-
+
def syntax(self):
if self.name:
return "<%s>" % self.name
return "<arg>"
+
class Constant(Parsable):
def __init__(self, text):
self.text = text
def syntax(self):
return self.text
-
+
def parse(self, parser, bits):
if not bits:
raise TemplateSyntaxError
@@ -65,17 +69,18 @@ def parse(self, parser, bits):
bits.popleft()
return None
raise TemplateSyntaxError
-
+
class Variable(NamedParsable):
def parse(self, parser, bits):
bit = bits.popleft()
val = parser.compile_filter(bit)
return [(self, self.name, val)]
-
+
def resolve(self, context, value):
return value.resolve(context)
+
class Name(NamedParsable):
def parse(self, parser, bits):
bit = bits.popleft()
@@ -85,10 +90,10 @@ def parse(self, parser, bits):
class Optional(Parsable):
def __init__(self, parts):
self.parts = parts
-
+
def syntax(self):
return "[%s]" % (" ".join(part.syntax() for part in self.parts))
-
+
def parse(self, parser, bits):
result = []
# we make a copy so that if part way through the optional part it

0 comments on commit 78e9f3d

Please sign in to comment.
Something went wrong with that request. Please try again.