summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-08-13 16:31:15 -0500
committerGerman M. Bravo <german.mb@deipi.com>2013-08-13 16:31:15 -0500
commitf21b085aff8c76398bda5eebbe83f1ee6ce4086f (patch)
tree291c30b15053074f702770d3930aa80769d737e7
parent7a0ba91fa621fb3262ae364444a1787ae70a42f3 (diff)
downloadpyscss-f21b085aff8c76398bda5eebbe83f1ee6ce4086f.tar.gz
PEP8 cleanups
-rw-r--r--scss/__init__.py2
-rw-r--r--scss/expression.py32
-rw-r--r--scss/functions/compass/helpers.py10
-rw-r--r--scss/rule.py1
-rw-r--r--scss/src/grammar/grammar.g1
-rw-r--r--scss/src/grammar/grammar.py1
-rw-r--r--scss/types.py5
7 files changed, 31 insertions, 21 deletions
diff --git a/scss/__init__.py b/scss/__init__.py
index 2100466..cb9061c 100644
--- a/scss/__init__.py
+++ b/scss/__init__.py
@@ -70,7 +70,7 @@ from scss.functions import ALL_BUILTINS_LIBRARY
from scss.functions.compass.sprites import sprite_map
from scss.rule import UnparsedBlock, SassRule
from scss.types import BooleanValue, List, Null, NumberValue, StringValue
-from scss.util import depar, dequote, normalize_var, split_params, to_str, profile, print_timing
+from scss.util import depar, dequote, normalize_var, split_params, profile, print_timing
log = logging.getLogger(__name__)
diff --git a/scss/expression.py b/scss/expression.py
index 8305bdc..0da97a4 100644
--- a/scss/expression.py
+++ b/scss/expression.py
@@ -11,7 +11,7 @@ import scss.config as config
from scss.cssdefs import COLOR_NAMES, is_builtin_css_function, _expr_glob_re, _interpolate_re, _variable_re
from scss.rule import Namespace
from scss.types import BooleanValue, ColorValue, ListValue, Null, NumberValue, ParserValue, String, Undefined
-from scss.util import dequote, normalize_var, to_str
+from scss.util import dequote, normalize_var
################################################################################
# Load C acceleration modules
@@ -97,7 +97,6 @@ class Calculator(object):
return better_expr_str
-
# TODO only used by magic-import...?
def interpolate(self, var):
value = self.namespace.variable(var)
@@ -107,7 +106,6 @@ class Calculator(object):
value = _vi
return value
-
def evaluate_expression(self, expr):
if not isinstance(expr, six.string_types):
raise TypeError("Expected string, got %r" % (expr,))
@@ -153,8 +151,6 @@ class Calculator(object):
return ast
-
-
# ------------------------------------------------------------------------------
# Expression classes -- the AST resulting from a parse
@@ -171,6 +167,7 @@ class Expression(object):
"""
raise NotImplementedError
+
class Parentheses(object):
"""An expression of the form `(foo)`.
@@ -183,6 +180,7 @@ class Parentheses(object):
def evaluate(self, calculator, divide=False):
return self.contents.evaluate(calculator, divide=True)
+
class UnaryOp(Expression):
def __init__(self, op, operand):
self.op = op
@@ -191,6 +189,7 @@ class UnaryOp(Expression):
def evaluate(self, calculator, divide=False):
return self.op(self.operand.evaluate(calculator, divide=True))
+
class BinaryOp(Expression):
def __init__(self, op, left, right):
self.op = op
@@ -208,15 +207,16 @@ 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.truediv
- and not divide
- and isinstance(self.left, Literal)
- and isinstance(self.right, Literal)
- ):
+ self.op is operator.truediv
+ and not divide
+ and isinstance(self.left, Literal)
+ and isinstance(self.right, Literal)
+ ):
return String(left.render() + ' / ' + right.render(), quotes=None)
return self.op(left, right)
+
class AnyOp(Expression):
def __init__(self, *operands):
self.operands = operands
@@ -225,6 +225,7 @@ class AnyOp(Expression):
operands = [operand.evaluate(calculator, divide=True) for operand in self.operands]
return BooleanValue(any(operands))
+
class AllOp(Expression):
def __init__(self, *operands):
self.operands = operands
@@ -233,6 +234,7 @@ class AllOp(Expression):
operands = [operand.evaluate(calculator, divide=True) for operand in self.operands]
return BooleanValue(all(operands))
+
class NotOp(Expression):
def __init__(self, operand):
self.operand = operand
@@ -241,6 +243,7 @@ class NotOp(Expression):
operand = self.operand.evaluate(calculator, divide=True)
return BooleanValue(not(operand))
+
class CallOp(Expression):
def __init__(self, func_name, argspec):
self.func_name = func_name
@@ -263,7 +266,7 @@ class CallOp(Expression):
if var is None:
args.append(value)
else:
- kwargs[ var.lstrip('$').replace('-', '_') ] = value
+ kwargs[var.lstrip('$').replace('-', '_')] = value
num_args = len(self.argspec.argpairs)
@@ -293,6 +296,7 @@ class CallOp(Expression):
else:
return func(*args, **kwargs)
+
class Literal(Expression):
def __init__(self, value):
self.value = value
@@ -300,6 +304,7 @@ class Literal(Expression):
def evaluate(self, calculator, divide=False):
return self.value
+
class Variable(Expression):
def __init__(self, name):
self.name = name
@@ -320,6 +325,7 @@ class Variable(Expression):
return evald
return value
+
class ListLiteral(Expression):
def __init__(self, items, comma=True):
self.items = items
@@ -329,6 +335,7 @@ class ListLiteral(Expression):
items = [item.evaluate(calculator, divide=divide) for item in self.items]
return ListValue(items, separator="," if self.comma else "")
+
class ArgspecLiteral(Expression):
"""Contains pairs of argument names and values, as parsed from a function
definition or function call.
@@ -377,8 +384,6 @@ def parse_bareword(word):
return String(word, quotes=None)
-
-
class Parser(object):
def __init__(self, scanner):
self._scanner = scanner
@@ -665,7 +670,6 @@ class SassExpression(Parser):
expr_slst_rsts = set(['LPAR', 'END', 'COLOR', 'QSTR', 'RPAR', 'VAR', 'ADD', 'NUM', 'COMMA', 'FNCT', 'STR', 'NOT', 'SIGN', 'ID'])
-
### Grammar ends.
################################################################################
diff --git a/scss/functions/compass/helpers.py b/scss/functions/compass/helpers.py
index ece0e2a..9de1d13 100644
--- a/scss/functions/compass/helpers.py
+++ b/scss/functions/compass/helpers.py
@@ -169,34 +169,42 @@ def prefix(prefix, *args):
def dash_moz(*args):
return prefix('_moz', *args)
+
@register('-svg')
def dash_svg(*args):
return prefix('_svg', *args)
+
@register('-css2')
def dash_css2(*args):
return prefix('_css2', *args)
+
@register('-pie')
def dash_pie(*args):
return prefix('_pie', *args)
+
@register('-webkit')
def dash_webkit(*args):
return prefix('_webkit', *args)
+
@register('-owg')
def dash_owg(*args):
return prefix('_owg', *args)
+
@register('-khtml')
def dash_khtml(*args):
return prefix('_khtml', *args)
+
@register('-ms')
def dash_ms(*args):
return prefix('_ms', *args)
+
@register('-o')
def dash_o(*args):
return prefix('_o', *args)
@@ -245,6 +253,7 @@ _elements_of_type = {
'html5': sorted(_elements_of_type_html5.replace(' ', '').split(',')),
}
+
@register('elements-of-type', 1)
def elements_of_type(display):
d = StringValue(display)
@@ -361,6 +370,7 @@ OPPOSITE_POSITIONS = dict(
center='center',
)
+
def _position(opposite, positions):
positions = List.from_maybe(positions)
diff --git a/scss/rule.py b/scss/rule.py
index 82ebe11..ea54873 100644
--- a/scss/rule.py
+++ b/scss/rule.py
@@ -16,6 +16,7 @@ def normalize_var(name):
else:
return name
+
class VariableScope(object):
"""Implements Sass variable scoping.
diff --git a/scss/src/grammar/grammar.g b/scss/src/grammar/grammar.g
index 6be39d4..b7c2af5 100644
--- a/scss/src/grammar/grammar.g
+++ b/scss/src/grammar/grammar.g
@@ -114,6 +114,5 @@ parser SassExpression:
expr {{ v.append(expr) }}
)* {{ return ListLiteral(v, comma=False) if len(v) > 1 else v[0] }}
%%
-
### Grammar ends.
################################################################################
diff --git a/scss/src/grammar/grammar.py b/scss/src/grammar/grammar.py
index 2b736d9..9526187 100644
--- a/scss/src/grammar/grammar.py
+++ b/scss/src/grammar/grammar.py
@@ -257,6 +257,5 @@ class SassExpression(Parser):
expr_slst_rsts = set(['LPAR', 'END', 'COLOR', 'QSTR', 'RPAR', 'VAR', 'ADD', 'NUM', 'COMMA', 'FNCT', 'STR', 'NOT', 'SIGN', 'ID'])
-
### Grammar ends.
################################################################################
diff --git a/scss/types.py b/scss/types.py
index d38cc10..47cf728 100644
--- a/scss/types.py
+++ b/scss/types.py
@@ -1,13 +1,12 @@
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
+from scss.util import escape
################################################################################
@@ -293,7 +292,6 @@ class Number(Value):
return NumberValue(new_amount, unit_numer=self.unit_numer, unit_denom=self.unit_denom)
-
### Helper methods, mostly used internally
def to_base_units(self):
@@ -314,7 +312,6 @@ class Number(Value):
unit_denom=denom_units,
)
-
### Utilities for public consumption
@classmethod