summaryrefslogtreecommitdiff
path: root/scss/types.py
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-10-08 06:34:10 -0700
committerGerman M. Bravo <german.mb@deipi.com>2013-10-08 06:34:10 -0700
commit3694d8087ea1a6d4764ee5829e37d98303b955af (patch)
treef0a473eab7bfacfd80098e069aa10fa26d20cf17 /scss/types.py
parente77cec393badc83cfa9ba9db3c494520b56ee739 (diff)
downloadpyscss-3694d8087ea1a6d4764ee5829e37d98303b955af.tar.gz
Allow for circular nth
Diffstat (limited to 'scss/types.py')
-rw-r--r--scss/types.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/scss/types.py b/scss/types.py
index 3351f7f..d0079d3 100644
--- a/scss/types.py
+++ b/scss/types.py
@@ -462,7 +462,7 @@ class Number(Value):
return wrapped
- def to_python_index(self, length, check_bounds=True):
+ def to_python_index(self, length, check_bounds=True, circular=False):
"""Return a plain Python integer appropriate for indexing a sequence of
the given length. Raise if this is impossible for any reason
whatsoever.
@@ -477,13 +477,16 @@ class Number(Value):
if ret == 0:
raise ValueError("Index cannot be zero")
- if check_bounds and abs(ret) > length:
+ if check_bounds and not circular and abs(ret) > length:
raise ValueError("Index {0!r} out of bounds for length {1}".format(ret, length))
if ret > 0:
- return ret - 1
- else:
- return ret
+ ret -= 1
+
+ if circular:
+ ret = ret % length
+
+ return ret
@property
def has_simple_unit(self):