diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-02 17:28:02 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-02 17:28:02 -0700 |
commit | 2879d05f396aa78cd252cf7dc0474fd3e55606d9 (patch) | |
tree | dbc90c0c482fe37079b176c04130ec0a488884f8 | |
parent | 2f035f1767107fd28a7f453485399e9b44b1de04 (diff) | |
download | pyscss-2879d05f396aa78cd252cf7dc0474fd3e55606d9.tar.gz |
Test suite passes (as well as it did before) on Py3!
-rw-r--r-- | scss/__init__.py | 6 | ||||
-rw-r--r-- | scss/expression.py | 4 | ||||
-rw-r--r-- | scss/functions/compass/images.py | 1 | ||||
-rw-r--r-- | scss/functions/compass/sprites.py | 2 | ||||
-rw-r--r-- | scss/functions/core.py | 1 | ||||
-rw-r--r-- | scss/functions/extra.py | 1 | ||||
-rwxr-xr-x | scss/src/block_locator.py | 2 | ||||
-rwxr-xr-x | scss/src/scanner.py | 2 | ||||
-rw-r--r-- | scss/types.py | 44 |
9 files changed, 40 insertions, 23 deletions
diff --git a/scss/__init__.py b/scss/__init__.py index 6ba4b9d..b9764b1 100644 --- a/scss/__init__.py +++ b/scss/__init__.py @@ -341,7 +341,7 @@ class Scss(object): self.source_files = [] self.source_file_index = {} if self._scss_files is not None: - for name, contents in self._scss_files.iteritems(): + for name, contents in list(self._scss_files.items()): if name in self.source_file_index: raise KeyError("Duplicate filename %r" % name) source_file = SourceFile(name, contents) @@ -1284,7 +1284,7 @@ class Scss(object): # To be able to manage multiple extends, you need to # destroy the actual node and create many nodes that have # mono extend. The first one gets all the css rules - for (selectors, parents), rules in grouped_rules.items(): + for (selectors, parents), rules in list(grouped_rules.items()): if len(parents) <= 1: continue @@ -1299,7 +1299,7 @@ class Scss(object): while parents_left and cnt < 10: cnt += 1 parents_left = False - for key in grouped_rules.keys(): + for key in list(grouped_rules.keys()): if key not in grouped_rules: # Nodes might have been renamed while linking parents... continue diff --git a/scss/expression.py b/scss/expression.py index 6bd2bec..e24733f 100644 --- a/scss/expression.py +++ b/scss/expression.py @@ -208,7 +208,7 @@ class BinaryOp(Expression): # covered by the `divide` argument: other nodes that perform arithmetic # will pass in True, indicating that this should always be a division. if ( - self.op is operator.div + self.op is operator.truediv and not divide and isinstance(self.left, Literal) and isinstance(self.right, Literal) @@ -521,7 +521,7 @@ class SassExpression(Parser): else: # == 'DIV' DIV = self._scan('DIV') u_expr = self.u_expr() - v = BinaryOp(operator.div, v, u_expr) + v = BinaryOp(operator.truediv, v, u_expr) return v def u_expr(self): diff --git a/scss/functions/compass/images.py b/scss/functions/compass/images.py index 1eeea38..d332684 100644 --- a/scss/functions/compass/images.py +++ b/scss/functions/compass/images.py @@ -11,6 +11,7 @@ import os.path import time import six +from six.moves import xrange from scss import config from scss.functions.compass import _image_size_cache diff --git a/scss/functions/compass/sprites.py b/scss/functions/compass/sprites.py index 6bf1131..a441e20 100644 --- a/scss/functions/compass/sprites.py +++ b/scss/functions/compass/sprites.py @@ -27,6 +27,8 @@ except ImportError: except: Image = None +from six.moves import xrange + from scss import config from scss.functions.compass import _image_size_cache from scss.functions.compass.layouts import PackedSpritesLayout, HorizontalSpritesLayout, VerticalSpritesLayout, DiagonalSpritesLayout diff --git a/scss/functions/core.py b/scss/functions/core.py index 887662b..dd4b00e 100644 --- a/scss/functions/core.py +++ b/scss/functions/core.py @@ -10,6 +10,7 @@ import math import operator import six +from six.moves import xrange from scss.cssdefs import _variable_re from scss.functions.library import FunctionLibrary diff --git a/scss/functions/extra.py b/scss/functions/extra.py index 6f4b274..66f05e6 100644 --- a/scss/functions/extra.py +++ b/scss/functions/extra.py @@ -9,6 +9,7 @@ import os.path import random import six +from six.moves import xrange from scss import config from scss.functions.library import FunctionLibrary diff --git a/scss/src/block_locator.py b/scss/src/block_locator.py index 7a2a55e..d4ffd74 100755 --- a/scss/src/block_locator.py +++ b/scss/src/block_locator.py @@ -7,6 +7,8 @@ import re import sys from datetime import datetime +from six.moves import xrange + import pstats import cProfile from cStringIO import StringIO diff --git a/scss/src/scanner.py b/scss/src/scanner.py index 0462cbf..a2463ec 100755 --- a/scss/src/scanner.py +++ b/scss/src/scanner.py @@ -7,6 +7,8 @@ import re import sys from datetime import datetime +from six.moves import xrange + import pstats import cProfile from cStringIO import StringIO diff --git a/scss/types.py b/scss/types.py index 412ab23..47d4f56 100644 --- a/scss/types.py +++ b/scss/types.py @@ -1,8 +1,11 @@ from __future__ import absolute_import +from __future__ import print_function import colorsys import operator +import six + from scss.cssdefs import COLOR_LOOKUP, COLOR_NAMES, ZEROABLE_UNITS, convert_units_to_base_units from scss.util import escape, to_float, to_str @@ -23,9 +26,13 @@ class Value(object): return '<%s: %s>' % (self.__class__.__name__, repr(self.value)) # Sass values are all true, except for booleans and nulls - def __nonzero__(self): + def __bool__(self): return True + def __nonzero__(self): + # Py 2's name for __bool__ + return self.__bool__() + ### NOTE: From here on down, the operators are exposed to Sass code and ### thus should ONLY return Sass types @@ -57,11 +64,11 @@ class Value(object): def __radd__(self, other): return self._do_op(other, self, operator.__add__) - def __div__(self, other): - return self._do_op(self, other, operator.__div__) + def __truediv__(self, other): + return self._do_op(self, other, operator.__truediv__) - def __rdiv__(self, other): - return self._do_op(other, self, operator.__div__) + def __rtruediv__(self, other): + return self._do_op(other, self, operator.__truediv__) def __sub__(self, other): return self._do_op(self, other, operator.__sub__) @@ -99,7 +106,7 @@ class Null(Value): def __repr__(self): return "<%s>" % (type(self).__name__,) - def __nonzero__(self): + def __bool__(self): return False def __eq__(self, other): @@ -118,7 +125,7 @@ class BooleanValue(Value): def __str__(self): return 'true' if self.value else 'false' - def __nonzero__(self): + def __bool__(self): return self.value @classmethod @@ -243,7 +250,7 @@ class NumberValue(Value): return NumberValue(amount, unit_numer=numer, unit_denom=denom) - def __div__(self, other): + def __truediv__(self, other): if not isinstance(other, NumberValue): return NotImplemented @@ -445,23 +452,20 @@ class ListValue(Value): def _reorder_list(self, lst): return dict((i if isinstance(k, int) else k, v) for i, (k, v) in enumerate(sorted(lst.items()))) - def __nonzero__(self): - return len(self) - def __len__(self): return len(self.value) - (1 if '_' in self.value else 0) def __str__(self): - return to_str(self.value) + return self.render() def __iter__(self): return iter(self.values()) def values(self): - return zip(*self.items())[1] + return list(zip(*self.items()))[1] def keys(self): - return zip(*self.items())[0] + return list(zip(*self.items()))[0] def items(self): return sorted((k, v) for k, v in self.value.items() if k != '_') @@ -715,17 +719,21 @@ class String(Value): # number values value = str(value) - if isinstance(value, str): + if isinstance(value, six.binary_type): # TODO this blows! need to be unicode-clean so this never happens. value = value.decode('ascii') - if not isinstance(value, unicode): - raise TypeError("Expected unicode, got {0!r}".format(value)) + if not isinstance(value, six.text_type): + raise TypeError("Expected string, got {0!r}".format(value)) # TODO probably disallow creating an unquoted string outside a # set of chars like [-a-zA-Z0-9]+ - self.value = value.encode('ascii') + if six.PY3: + self.value = value + else: + # TODO not unicode clean on 2 yet... + self.value = value.encode('ascii') self.quotes = quotes def __str__(self): |