Kirill Simonov avatar Kirill Simonov committed 435885d

Renames: `Val` -> `Validator`, `*Expression` -> `*Expr`.

Comments (0)

Files changed (8)

src/htsql/ctl/option.py

 
 
 from ..util import maybe
-from ..validator import Val, StrVal
+from ..validator import Validator, StrVal
 import re
 
 
     `value_name` (a string or ``None``)
         The name of the option parameter.
 
-    `validator` (:class:`htsql.validator.Val` or ``None``)
+    `validator` (:class:`htsql.validator.Validator` or ``None``)
         The validator for the option parameter.
 
     `default`
         assert short_name is not None or long_name is not None
         assert isinstance(with_value, bool)
         assert isinstance(value_name, maybe(str))
-        assert isinstance(validator, maybe(Val))
+        assert isinstance(validator, maybe(Validator))
         if with_value:
             assert validator is not None
         else:

src/htsql/ctl/regress.py

 from .option import (InputOption, TrainOption, PurgeOption,
                      ForceOption, QuietOption)
 from .request import Request
-from ..validator import (Val, AnyVal, BoolVal, StrVal, WordVal, ChoiceVal,
-                         IntVal, UFloatVal, DBVal, SeqVal, MapVal, ClassVal)
+from ..validator import (Validator, AnyVal, BoolVal, StrVal, WordVal,
+                         ChoiceVal, IntVal, UFloatVal, DBVal, SeqVal,
+                         MapVal, ClassVal)
 from ..util import maybe, trim_doc, DB
 import traceback
 import StringIO
     `attribute` (a string)
         The name of the attribute that contains the field value.
 
-    `validator` (:class:`htsql.validator.Val`)
+    `val` (:class:`htsql.validator.Validator`)
         The validator for the field values.
 
     `default`
     # Use it to filter out `AnyField` instances.
     is_any = False
 
-    def __init__(self, attribute, validator,
+    def __init__(self, attribute, val,
                  default=MANDATORY_FIELD, hint=None):
         # Sanity check on the arguments.
         assert isinstance(attribute, str)
         assert re.match(r'^[a-zA-Z_][0-9a-zA-Z_]*$', attribute)
-        assert isinstance(validator, Val)
+        assert isinstance(val, Validator)
         assert isinstance(hint, maybe(str))
 
         self.attribute = attribute
-        self.validator = validator
+        self.val = val
         self.default = default
         self.is_mandatory = (default is MANDATORY_FIELD)
         self.hint = hint
             if key in value_by_key:
                 value = value_by_key[key]
                 try:
-                    value = field.validator(value)
+                    value = field.val(value)
                 except ValueError, exc:
                     raise yaml.constructor.ConstructorError(None, None,
                             "invalid field %r (%s)" % (key, exc),

src/htsql/ctl/routine.py

 
 
 from .error import ScriptError
-from ..validator import Val
+from ..validator import Validator
 from ..util import maybe, trim_doc
 import re
 
         initialized, the value of the argument is assigned to
         the attribute.
 
-    `validator` (:class:`htsql.validator.Val`)
+    `validator` (:class:`htsql.validator.Validator`)
         The validator for the argument value.
 
     `default`
         # Sanity check on the arguments.
         assert isinstance(attribute, str)
         assert re.match(r'^[a-zA-Z_][0-9a-zA-Z_]*$', attribute)
-        assert isinstance(validator, Val)
+        assert isinstance(validator, Validator)
         assert isinstance(is_list, bool)
         assert isinstance(hint, maybe(str))
 

src/htsql/tr/code.py

         return str(self.syntax)
 
 
-class QueryExpression(Expression):
+class QueryExpr(Expression):
     """
     Represents a whole HTSQL query.
 
-    `segment` (:class:`SegmentExpression` or ``None``)
+    `segment` (:class:`SegmentExpr` or ``None``)
         The query segment.
     """
 
     def __init__(self, segment, binding):
-        assert isinstance(segment, maybe(SegmentExpression))
+        assert isinstance(segment, maybe(SegmentExpr))
         assert isinstance(binding, QueryBinding)
-        super(QueryExpression, self).__init__(binding)
+        super(QueryExpr, self).__init__(binding)
         self.segment = segment
 
 
-class SegmentExpression(Expression):
+class SegmentExpr(Expression):
     """
     Represents a segment of an HTSQL query.
 
         assert isinstance(space, Space)
         assert isinstance(elements, listof(Code))
         assert isinstance(binding, SegmentBinding)
-        super(SegmentExpression, self).__init__(binding)
+        super(SegmentExpr, self).__init__(binding)
         self.space = space
         self.elements = elements
 
     """
 
 
-class BatchExpression(Expression):
+class BatchExpr(Expression):
     """
     Represents a collection of expression nodes.
 
 
     def __init__(self, collection, binding):
         assert isinstance(collection, listof(Expression))
-        super(BatchExpression, self).__init__(binding)
+        super(BatchExpr, self).__init__(binding)
         self.collection = collection
 
     def __str__(self):
                                   for expression in self.collection)
 
 
-class ScalarBatchExpression(BatchExpression):
+class ScalarBatchExpr(BatchExpr):
     """
     Represents a collection of sclar units sharing the same base space.
 
         assert isinstance(space, Space)
         assert isinstance(collection, listof(ScalarUnit))
         assert all(space == unit.space for unit in collection)
-        super(ScalarBatchExpression, self).__init__(collection, binding)
+        super(ScalarBatchExpr, self).__init__(collection, binding)
         self.space = space
 
 
-class AggregateBatchExpression(BatchExpression):
+class AggregateBatchExpr(BatchExpr):
     """
     Represents a collection of aggregate units sharing the same base and
     plural spaces.
         assert isinstance(collection, listof(AggregateUnit))
         assert all(plural_space == unit.plural_space and space == unit.space
                    for unit in collection)
-        super(AggregateBatchExpression, self).__init__(collection, binding)
+        super(AggregateBatchExpr, self).__init__(collection, binding)
         self.plural_space = plural_space
         self.space = space
 

src/htsql/tr/compile.py

                    DirectProductSpace, FiberProductSpace,
                    FilteredSpace, OrderedSpace, MaskedSpace,
                    Unit, ScalarUnit, ColumnUnit, AggregateUnit, CorrelatedUnit,
-                   QueryExpression, SegmentExpression,
-                   BatchExpression, ScalarBatchExpression,
-                   AggregateBatchExpression)
+                   QueryExpr, SegmentExpr, BatchExpr, ScalarBatchExpr,
+                   AggregateBatchExpr)
 from .term import (PreTerm, Term, ScalarTerm, TableTerm, FilterTerm, JoinTerm,
                    EmbeddingTerm, CorrelationTerm, ProjectionTerm, OrderTerm,
                    WrapperTerm, SegmentTerm, QueryTerm)
         # term tree when it processes all units sharing the same
         # form simultaneously.  To handle this case, we collect
         # all expressions into an auxiliary expression node
-        # `BatchExpression`.  When injected, the group expression
+        # `BatchExpr`.  When injected, the group expression
         # applies the multi-unit optimizations.
         if len(expressions) == 1:
             expression = expressions[0]
         else:
-            expression = BatchExpression(expressions, term.binding)
+            expression = BatchExpr(expressions, term.binding)
         # Realize and apply the `Inject` adapter.
         inject = Inject(expression, term, self)
         return inject()
     Compiles a top-level query term.
     """
 
-    adapts(QueryExpression)
+    adapts(QueryExpr)
 
     def __call__(self):
         # Compile the segment term.
     Compiles a segment term.
     """
 
-    adapts(SegmentExpression)
+    adapts(SegmentExpr)
 
     def __call__(self):
         # Initialize the all state spaces with a scalar space.
         if self.unit in self.term.routes:
             return self.term
         # Form a batch consisting of a single unit.
-        batch = ScalarBatchExpression(self.unit.space, [self.unit],
-                                      self.unit.binding)
+        batch = ScalarBatchExpr(self.unit.space, [self.unit],
+                                self.unit.binding)
         # Delegate the injecting to the batch.
         return self.state.inject(self.term, [batch])
 
         if self.unit in self.term.routes:
             return self.term
         # Form a batch consisting of a single unit.
-        batch = AggregateBatchExpression(self.unit.plural_space,
-                                         self.unit.space, [self.unit],
-                                         self.unit.binding)
+        batch = AggregateBatchExpr(self.unit.plural_space,
+                                   self.unit.space, [self.unit],
+                                   self.unit.binding)
         # Delegate the injecting to the batch.
         return self.state.inject(self.term, [batch])
 
     Injects a batch of expressions into a term.
     """
 
-    adapts(BatchExpression)
+    adapts(BatchExpr)
 
     def __init__(self, expression, term, state):
         super(InjectBatch, self).__init__(expression, term, state)
         # Form and inject batches of matching scalar units.
         for space in scalar_spaces:
             batch_units = scalar_space_to_units[space]
-            batch = ScalarBatchExpression(space, batch_units,
-                                          self.term.binding)
+            batch = ScalarBatchExpr(space, batch_units,
+                                    self.term.binding)
             term = self.state.inject(term, [batch])
 
         # Find all aggregate units and group them by their plural and unit
         for pair in aggregate_space_pairs:
             plural_space, space = pair
             group_units = aggregate_space_pair_to_units[pair]
-            group = AggregateBatchExpression(plural_space, space, group_units,
-                                             self.term.binding)
+            group = AggregateBatchExpr(plural_space, space, group_units,
+                                       self.term.binding)
             term = self.state.inject(term, [group])
 
         # Finally, just take and inject all the given expressions.  We don't
     Injects a batch of scalar units sharing the same space.
     """
 
-    adapts(ScalarBatchExpression)
+    adapts(ScalarBatchExpr)
 
     def __init__(self, expression, term, state):
         super(InjectScalarBatch, self).__init__(expression, term, state)
     Injects a batch of aggregate units sharing the same plural and unit spaces.
     """
 
-    adapts(AggregateBatchExpression)
+    adapts(AggregateBatchExpr)
 
     def __init__(self, expression, term, state):
         super(InjectAggregateBatch, self).__init__(expression, term, state)

src/htsql/tr/encode.py

                       DirectionBinding)
 from .code import (ScalarSpace, DirectProductSpace, FiberProductSpace,
                    FilteredSpace, OrderedSpace,
-                   QueryExpression, SegmentExpression, LiteralCode,
+                   QueryExpr, SegmentExpr, LiteralCode,
                    EqualityCode, TotalEqualityCode,
                    ConjunctionCode, DisjunctionCode, NegationCode,
                    CastCode, ColumnUnit, ScalarUnit)
     """
     Encodes the top-level binding node :class:`htsql.tr.binding.QueryBinding`.
 
-    Produces an instance of :class:`htsql.tr.code.QueryExpression`.
+    Produces an instance of :class:`htsql.tr.code.QueryExpr`.
     """
 
     adapts(QueryBinding)
         if self.binding.segment is not None:
             segment = self.state.encode(self.binding.segment)
         # Construct the expression node.
-        return QueryExpression(segment, self.binding)
+        return QueryExpr(segment, self.binding)
 
 
 class EncodeSegment(Encode):
     """
     Encodes a segment binding node :class:`htsql.tr.binding.SegmentBinding`.
 
-    Produces an instance of :class:`htsql.tr.code.SegmentExpression`.
+    Produces an instance of :class:`htsql.tr.code.SegmentExpr`.
     """
 
     adapts(SegmentBinding)
         if order:
             space = OrderedSpace(space, order, None, None, self.binding)
         # Construct the expression node.
-        return SegmentExpression(space, elements, self.binding)
+        return SegmentExpr(space, elements, self.binding)
 
 
 class RelateRoot(Relate):

src/htsql/tr/term.py

 from ..util import (listof, dictof, oneof, tupleof, maybe,
                     Clonable, Printable)
 from ..domain import BooleanDomain
-from .code import Expression, Space, Code, Unit, QueryExpression
+from .code import Expression, Space, Code, Unit, QueryExpr
 
 
 class PreTerm(Clonable, Printable):
 
     def __init__(self, segment, expression):
         assert isinstance(segment, maybe(SegmentTerm))
-        assert isinstance(expression, QueryExpression)
+        assert isinstance(expression, QueryExpr)
         super(QueryTerm, self).__init__(expression)
         self.segment = segment
 

src/htsql/validator.py

 import re
 
 
-class Val(object):
+class Validator(object):
     """
     Validators check if a given value conforms the specified format.
 
 
     Attribute `hint` gives a short textual description of the format.
 
-    :class:`Val` is the base abstract class for validators.  Its subclasses
-    provide validators for specific formats.
+    :class:`Validator` is the base abstract class for validators.  Its
+    subclasses provide validators for specific formats.
 
-    To create a validator for a new format, create a subclass of :class:`Val`
-    and override the :meth:`__call__()` method.  The method should accept
-    values of any type.  If the value does not conform to the format,
-    :exc:`ValueError` should be raised; otherwise the value should be
-    normalized and returned.
+    To create a validator for a new format, create a subclass of
+    :class:`Validator` and override the :meth:`__call__()` method.  The
+    method should accept values of any type.  If the value does not conform
+    to the format, :exc:`ValueError` should be raised; otherwise the value
+    should be normalized and returned.
 
     Example::
 
-        class IntVal(Val):
+        class IntVal(Validator):
 
             hint = "an integer"
 
         return self.hint
 
 
-class AnyVal(Val):
+class AnyVal(Validator):
     """
     A no-op validator.
     """
         return value
 
 
-class StrVal(Val):
+class StrVal(Validator):
     """
     Verifies if the value is a UTF-8 encoded string.
 
         return value
 
 
-class WordVal(Val):
+class WordVal(Validator):
     """
     Verifies if the value is a word.
 
         return value
 
 
-class ChoiceVal(Val):
+class ChoiceVal(Validator):
     """
     Verifies if the value belongs to a specified set of string constants.
 
         return value
 
 
-class BoolVal(Val):
+class BoolVal(Validator):
     """
     Verifies if the value is Boolean.
 
         return value
 
 
-class IntVal(Val):
+class IntVal(Validator):
     """
     Verifies if the value is an integer.
 
         super(PIntVal, self).__init__(1, max_bound, is_nullable)
 
 
-class FloatVal(Val):
+class FloatVal(Validator):
     """
     Verifies if the value is an integer.
 
         super(UFloatVal, self).__init__(0, max_bound, is_nullable)
 
 
-class SeqVal(Val):
+class SeqVal(Validator):
     """
     Verifies if the value is a list with each list item conforming
     the specified format.
     be represented literally; otherwise it should be quited with ``'`` and
     any single quote character should be duplicated.
 
-    `item_validator` (:class:`Val`)
+    `item_validator` (:class:`Validator`)
         Validator for the sequence elements.
 
     `length` (an integer or ``None``)
 
     def __init__(self, item_validator, length=None, is_nullable=False):
         # Sanity check on the arguments.
-        assert isinstance(item_validator, Val)
+        assert isinstance(item_validator, Validator)
         assert isinstance(length, maybe(int))
         assert isinstance(is_nullable, bool)
 
         return value
 
 
-class MapVal(Val):
+class MapVal(Validator):
     """
     Verifies if the value is a dictionary with keys and items conforming
     the specified formats.
     element is enclosed with ``'`` and has any single quote character
     duplicated.
 
-    `key_validator` (:class:`Val`)
+    `key_validator` (:class:`Validator`)
         Validator for the mapping keys.
 
-    `item_validator` (:class:`Val`)
+    `item_validator` (:class:`Validator`)
         Validator for the mapping values.
 
     `is_nullable` (Boolean)
 
     def __init__(self, key_validator, item_validator, is_nullable=False):
         # Sanity check on the arguments.
-        assert isinstance(key_validator, Val)
-        assert isinstance(item_validator, Val)
+        assert isinstance(key_validator, Validator)
+        assert isinstance(item_validator, Validator)
         assert isinstance(is_nullable, bool)
 
         self.key_validator = key_validator
         return value
 
 
-class ClassVal(Val):
+class ClassVal(Validator):
     """
     Verifies if the value is an instance of the specified class.
 
         return value
 
 
-class DBVal(Val):
+class DBVal(Validator):
     """
     Verifies if the value is a connection URI.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.