Remove six
Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Change-Id: I2f37e055838ea50627562d3585d6951f8d8d46aa
This commit is contained in:
parent
8fcac72fd3
commit
4670f0949c
@ -13,12 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import io
|
||||||
import operator
|
import operator
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import traceback
|
import traceback
|
||||||
import types
|
import types
|
||||||
|
|
||||||
import six
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers import rst
|
from docutils.parsers import rst
|
||||||
from docutils import utils
|
from docutils import utils
|
||||||
@ -123,7 +123,7 @@ def write_module_doc(module, output):
|
|||||||
method = getattr(module, name)
|
method = getattr(module, name)
|
||||||
it = write_method_doc(method, output)
|
it = write_method_doc(method, output)
|
||||||
try:
|
try:
|
||||||
name = six.next(it)
|
name = next(it)
|
||||||
seq.append((name, it))
|
seq.append((name, it))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
@ -169,7 +169,7 @@ def generate_doc(source):
|
|||||||
package = importlib.import_module(source)
|
package = importlib.import_module(source)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return 'Error: No such module {0}'.format(source)
|
return 'Error: No such module {0}'.format(source)
|
||||||
out = six.StringIO()
|
out = io.StringIO()
|
||||||
try:
|
try:
|
||||||
if hasattr(package, '__path__'):
|
if hasattr(package, '__path__'):
|
||||||
write_package_doc(package, out)
|
write_package_doc(package, out)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
pbr>=1.8
|
pbr>=1.8
|
||||||
python-dateutil>=2.4.2
|
python-dateutil>=2.4.2
|
||||||
ply
|
ply
|
||||||
six>=1.9.0
|
|
||||||
|
@ -13,16 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import locale
|
|
||||||
import os
|
import os
|
||||||
import readline
|
import readline
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language.exceptions import YaqlParsingException
|
|
||||||
|
|
||||||
from yaql import __version__ as version
|
from yaql import __version__ as version
|
||||||
|
from yaql.language.exceptions import YaqlParsingException
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
|
|
||||||
|
|
||||||
@ -46,10 +42,7 @@ def main(context, show_tokens, parser):
|
|||||||
comm = True
|
comm = True
|
||||||
while comm != 'exit':
|
while comm != 'exit':
|
||||||
try:
|
try:
|
||||||
comm = six.moves.input(PROMPT)
|
comm = input(PROMPT)
|
||||||
if six.PY2:
|
|
||||||
comm = comm.decode(
|
|
||||||
sys.stdin.encoding or locale.getpreferredencoding(True))
|
|
||||||
except EOFError:
|
except EOFError:
|
||||||
return
|
return
|
||||||
if not comm:
|
if not comm:
|
||||||
|
@ -14,16 +14,13 @@
|
|||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import runner
|
from yaql.language import runner
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class ContextBase(metaclass=abc.ABCMeta):
|
||||||
class ContextBase(object):
|
|
||||||
def __init__(self, parent_context=None, convention=None):
|
def __init__(self, parent_context=None, convention=None):
|
||||||
self._parent_context = parent_context
|
self._parent_context = parent_context
|
||||||
self._convention = convention
|
self._convention = convention
|
||||||
@ -95,7 +92,7 @@ class ContextBase(object):
|
|||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def keys(self):
|
def keys(self):
|
||||||
return six.iterkeys({})
|
return {}.keys()
|
||||||
|
|
||||||
|
|
||||||
class Context(ContextBase):
|
class Context(ContextBase):
|
||||||
@ -115,8 +112,7 @@ class Context(ContextBase):
|
|||||||
def register_function(self, spec, *args, **kwargs):
|
def register_function(self, spec, *args, **kwargs):
|
||||||
exclusive = kwargs.pop('exclusive', False)
|
exclusive = kwargs.pop('exclusive', False)
|
||||||
|
|
||||||
if not isinstance(spec, specs.FunctionDefinition) \
|
if not isinstance(spec, specs.FunctionDefinition) and callable(spec):
|
||||||
and six.callable(spec):
|
|
||||||
spec = specs.get_function_definition(
|
spec = specs.get_function_definition(
|
||||||
spec, *args, convention=self._convention, **kwargs)
|
spec, *args, convention=self._convention, **kwargs)
|
||||||
|
|
||||||
@ -139,7 +135,7 @@ class Context(ContextBase):
|
|||||||
if predicate is None:
|
if predicate is None:
|
||||||
predicate = lambda x: True # noqa: E731
|
predicate = lambda x: True # noqa: E731
|
||||||
return (
|
return (
|
||||||
set(six.moves.filter(predicate, self._functions.get(name, set()))),
|
set(filter(predicate, self._functions.get(name, set()))),
|
||||||
name in self._exclusive_funcs
|
name in self._exclusive_funcs
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -173,12 +169,12 @@ class Context(ContextBase):
|
|||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
if isinstance(item, specs.FunctionDefinition):
|
if isinstance(item, specs.FunctionDefinition):
|
||||||
return item in self._functions.get(item.name, [])
|
return item in self._functions.get(item.name, [])
|
||||||
if isinstance(item, six.string_types):
|
if isinstance(item, str):
|
||||||
return self._normalize_name(item) in self._data
|
return self._normalize_name(item) in self._data
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
return six.iterkeys(self._data)
|
return self._data.keys()
|
||||||
|
|
||||||
|
|
||||||
class MultiContext(ContextBase):
|
class MultiContext(ContextBase):
|
||||||
@ -186,9 +182,9 @@ class MultiContext(ContextBase):
|
|||||||
self._context_list = context_list
|
self._context_list = context_list
|
||||||
if convention is None:
|
if convention is None:
|
||||||
convention = context_list[0].convention
|
convention = context_list[0].convention
|
||||||
parents = tuple(six.moves.filter(
|
parents = tuple(
|
||||||
lambda t: t,
|
filter(lambda t: t, map(lambda t: t.parent, context_list))
|
||||||
six.moves.map(lambda t: t.parent, context_list)))
|
)
|
||||||
if not parents:
|
if not parents:
|
||||||
super(MultiContext, self).__init__(None, convention)
|
super(MultiContext, self).__init__(None, convention)
|
||||||
elif len(parents) == 1:
|
elif len(parents) == 1:
|
||||||
|
@ -15,11 +15,8 @@
|
|||||||
import abc
|
import abc
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
class Convention(metaclass=abc.ABCMeta):
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
|
||||||
class Convention(object):
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def convert_function_name(self, name):
|
def convert_function_name(self, name):
|
||||||
pass
|
pass
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import yaql
|
import yaql
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
@ -26,7 +24,6 @@ class Expression(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Function(Expression):
|
class Function(Expression):
|
||||||
def __init__(self, name, *args):
|
def __init__(self, name, *args):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -37,8 +34,7 @@ class Function(Expression):
|
|||||||
return context(self.name, engine, receiver, context)(*self.args)
|
return context(self.name, engine, receiver, context)(*self.args)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{0}({1})'.format(self.name, ', '.join(
|
return '{0}({1})'.format(self.name, ', '.join(map(str, self.args)))
|
||||||
map(six.text_type, self.args)))
|
|
||||||
|
|
||||||
|
|
||||||
class BinaryOperator(Function):
|
class BinaryOperator(Function):
|
||||||
@ -81,7 +77,6 @@ class MapExpression(Function):
|
|||||||
self.uses_receiver = False
|
self.uses_receiver = False
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class GetContextValue(Function):
|
class GetContextValue(Function):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super(GetContextValue, self).__init__('#get_context_data', path)
|
super(GetContextValue, self).__init__('#get_context_data', path)
|
||||||
@ -92,16 +87,15 @@ class GetContextValue(Function):
|
|||||||
return self.path.value
|
return self.path.value
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Constant(Expression):
|
class Constant(Expression):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
self.uses_receiver = False
|
self.uses_receiver = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if isinstance(self.value, six.text_type):
|
if isinstance(self.value, str):
|
||||||
return u"'{0}'".format(self.value)
|
return "'{0}'".format(self.value)
|
||||||
return six.text_type(self.value)
|
return str(self.value)
|
||||||
|
|
||||||
def __call__(self, receiver, context, engine):
|
def __call__(self, receiver, context, engine):
|
||||||
return self.value
|
return self.value
|
||||||
@ -111,7 +105,6 @@ class KeywordConstant(Constant):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Wrap(Expression):
|
class Wrap(Expression):
|
||||||
def __init__(self, expression):
|
def __init__(self, expression):
|
||||||
self.expr = expression
|
self.expr = expression
|
||||||
@ -124,7 +117,6 @@ class Wrap(Expression):
|
|||||||
return self.expr(receiver, context, engine)
|
return self.expr(receiver, context, engine)
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class MappingRuleExpression(Expression):
|
class MappingRuleExpression(Expression):
|
||||||
def __init__(self, source, destination):
|
def __init__(self, source, destination):
|
||||||
self.source = source
|
self.source = source
|
||||||
@ -140,7 +132,6 @@ class MappingRuleExpression(Expression):
|
|||||||
self.destination(receiver, context, engine))
|
self.destination(receiver, context, engine))
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Statement(Function):
|
class Statement(Function):
|
||||||
def __init__(self, expression, engine):
|
def __init__(self, expression, engine):
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
@ -155,7 +146,7 @@ class Statement(Function):
|
|||||||
try:
|
try:
|
||||||
return super(Statement, self).__call__(receiver, context, engine)
|
return super(Statement, self).__call__(receiver, context, engine)
|
||||||
except exceptions.WrappedException as e:
|
except exceptions.WrappedException as e:
|
||||||
six.reraise(type(e.wrapped), e.wrapped, sys.exc_info()[2])
|
raise e.wrapped.with_traceback(sys.exc_info()[2])
|
||||||
|
|
||||||
def evaluate(self, data=utils.NO_VALUE, context=None):
|
def evaluate(self, data=utils.NO_VALUE, context=None):
|
||||||
if context is None or context is utils.NO_VALUE:
|
if context is None or context is utils.NO_VALUE:
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +64,7 @@ class Lexer(object):
|
|||||||
'MAPPING',
|
'MAPPING',
|
||||||
'MAP'
|
'MAP'
|
||||||
] + list(self.keywords.values())
|
] + list(self.keywords.values())
|
||||||
for op_symbol, op_record in six.iteritems(self._operators_table):
|
for op_symbol, op_record in self._operators_table.items():
|
||||||
if op_symbol in ('[]', '{}'):
|
if op_symbol in ('[]', '{}'):
|
||||||
continue
|
continue
|
||||||
lexem_name = op_record[2]
|
lexem_name = op_record[2]
|
||||||
|
4757
yaql/language/parser.out
Normal file
4757
yaql/language/parser.out
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
import types
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import expressions
|
from yaql.language import expressions
|
||||||
@ -71,9 +71,9 @@ class Parser(object):
|
|||||||
p[0] = expressions.UnaryOperator(p[2], p[1], alias)
|
p[0] = expressions.UnaryOperator(p[2], p[1], alias)
|
||||||
|
|
||||||
p_binary.__doc__ = binary_doc
|
p_binary.__doc__ = binary_doc
|
||||||
self.p_binary = six.create_bound_method(p_binary, self)
|
self.p_binary = types.MethodType(p_binary, self)
|
||||||
p_unary.__doc__ = unary_doc
|
p_unary.__doc__ = unary_doc
|
||||||
self.p_unary = six.create_bound_method(p_unary, self)
|
self.p_unary = types.MethodType(p_unary, self)
|
||||||
|
|
||||||
precedence = []
|
precedence = []
|
||||||
for i in range(1, len(precedence_dict) + 1):
|
for i in range(1, len(precedence_dict) + 1):
|
||||||
@ -98,7 +98,7 @@ class Parser(object):
|
|||||||
p[0] = expressions.Function('#call', p[1], *arg)
|
p[0] = expressions.Function('#call', p[1], *arg)
|
||||||
|
|
||||||
if engine.allow_delegates:
|
if engine.allow_delegates:
|
||||||
self.p_value_call = six.create_bound_method(p_value_call, self)
|
self.p_value_call = types.MethodType(p_value_call, self)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def p_value_to_const(p):
|
def p_value_to_const(p):
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import expressions
|
from yaql.language import expressions
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
@ -54,9 +52,7 @@ def call(name, context, args, kwargs, engine, receiver=utils.NO_VALUE,
|
|||||||
utils.limit_memory_usage(engine, (1, result))
|
utils.limit_memory_usage(engine, (1, result))
|
||||||
return result
|
return result
|
||||||
except StopIteration as e:
|
except StopIteration as e:
|
||||||
six.reraise(
|
raise exceptions.WrappedException(e).with_traceback(
|
||||||
exceptions.WrappedException,
|
|
||||||
exceptions.WrappedException(e),
|
|
||||||
sys.exc_info()[2])
|
sys.exc_info()[2])
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +91,7 @@ def choose_overload(name, candidates, engine, receiver, context, args, kwargs):
|
|||||||
for i, pos_arg in enumerate(pos):
|
for i, pos_arg in enumerate(pos):
|
||||||
if isinstance(pos_arg.value_type, yaqltypes.LazyParameterType):
|
if isinstance(pos_arg.value_type, yaqltypes.LazyParameterType):
|
||||||
lazy.add(i)
|
lazy.add(i)
|
||||||
for key, value in six.iteritems(kwd):
|
for key, value in kwd.items():
|
||||||
if isinstance(value.value_type, yaqltypes.LazyParameterType):
|
if isinstance(value.value_type, yaqltypes.LazyParameterType):
|
||||||
lazy.add(key)
|
lazy.add(key)
|
||||||
if lazy_params is None:
|
if lazy_params is None:
|
||||||
@ -117,7 +113,7 @@ def choose_overload(name, candidates, engine, receiver, context, args, kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
args = tuple(arg_evaluator(i, arg) for i, arg in enumerate(args))
|
args = tuple(arg_evaluator(i, arg) for i, arg in enumerate(args))
|
||||||
for key, value in six.iteritems(kwargs):
|
for key, value in kwargs.items():
|
||||||
kwargs[key] = arg_evaluator(key, value)
|
kwargs[key] = arg_evaluator(key, value)
|
||||||
|
|
||||||
delegate = None
|
delegate = None
|
||||||
@ -147,7 +143,7 @@ def choose_overload(name, candidates, engine, receiver, context, args, kwargs):
|
|||||||
def translate_args(without_kwargs, args, kwargs):
|
def translate_args(without_kwargs, args, kwargs):
|
||||||
if without_kwargs:
|
if without_kwargs:
|
||||||
if len(kwargs) > 0:
|
if len(kwargs) > 0:
|
||||||
raise exceptions.ArgumentException(six.next(iter(kwargs)))
|
raise exceptions.ArgumentException(next(iter(kwargs)))
|
||||||
return args, {}
|
return args, {}
|
||||||
pos_args = []
|
pos_args = []
|
||||||
kw_args = {}
|
kw_args = {}
|
||||||
@ -161,7 +157,7 @@ def translate_args(without_kwargs, args, kwargs):
|
|||||||
kw_args[param_name] = t.destination
|
kw_args[param_name] = t.destination
|
||||||
else:
|
else:
|
||||||
pos_args.append(t)
|
pos_args.append(t)
|
||||||
for key, value in six.iteritems(kwargs):
|
for key, value in kwargs.items():
|
||||||
if key in kw_args:
|
if key in kw_args:
|
||||||
raise exceptions.MappingTranslationException()
|
raise exceptions.MappingTranslationException()
|
||||||
else:
|
else:
|
||||||
@ -174,13 +170,13 @@ def _is_specialization_of(mapping1, mapping2):
|
|||||||
args_mapping2, kwargs_mapping2 = mapping2
|
args_mapping2, kwargs_mapping2 = mapping2
|
||||||
res = False
|
res = False
|
||||||
|
|
||||||
for a1, a2 in six.moves.zip(args_mapping1, args_mapping2):
|
for a1, a2 in zip(args_mapping1, args_mapping2):
|
||||||
if a2.value_type.is_specialization_of(a1.value_type):
|
if a2.value_type.is_specialization_of(a1.value_type):
|
||||||
return False
|
return False
|
||||||
elif a1.value_type.is_specialization_of(a2.value_type):
|
elif a1.value_type.is_specialization_of(a2.value_type):
|
||||||
res = True
|
res = True
|
||||||
|
|
||||||
for key, a1 in six.iteritems(kwargs_mapping1):
|
for key, a1 in kwargs_mapping1.items():
|
||||||
a2 = kwargs_mapping2[key]
|
a2 = kwargs_mapping2[key]
|
||||||
if a2.value_type.is_specialization_of(a1.value_type):
|
if a2.value_type.is_specialization_of(a1.value_type):
|
||||||
return False
|
return False
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
@ -66,9 +64,7 @@ class FunctionDefinition(object):
|
|||||||
return func
|
return func
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
parameters = dict(
|
parameters = {key: p.clone() for key, p in self.parameters.items()}
|
||||||
(key, p.clone())
|
|
||||||
for key, p in six.iteritems(self.parameters))
|
|
||||||
|
|
||||||
res = FunctionDefinition(
|
res = FunctionDefinition(
|
||||||
self.name, self.payload, parameters, self.doc,
|
self.name, self.payload, parameters, self.doc,
|
||||||
@ -79,12 +75,12 @@ class FunctionDefinition(object):
|
|||||||
fd = self.clone()
|
fd = self.clone()
|
||||||
keys_to_remove = set()
|
keys_to_remove = set()
|
||||||
|
|
||||||
for k, v in six.iteritems(fd.parameters):
|
for k, v in fd.parameters.items():
|
||||||
if not isinstance(v.value_type, yaqltypes.HiddenParameterType):
|
if not isinstance(v.value_type, yaqltypes.HiddenParameterType):
|
||||||
continue
|
continue
|
||||||
keys_to_remove.add(k)
|
keys_to_remove.add(k)
|
||||||
if v.position is not None:
|
if v.position is not None:
|
||||||
for v2 in six.itervalues(fd.parameters):
|
for v2 in fd.parameters.values():
|
||||||
if v2.position is not None and v2.position > v.position:
|
if v2.position is not None and v2.position > v.position:
|
||||||
v2.position -= 1
|
v2.position -= 1
|
||||||
for key in keys_to_remove:
|
for key in keys_to_remove:
|
||||||
@ -101,35 +97,6 @@ class FunctionDefinition(object):
|
|||||||
self.parameters[name.name] = name
|
self.parameters[name.name] = name
|
||||||
return name
|
return name
|
||||||
|
|
||||||
if six.PY2:
|
|
||||||
spec = inspect.getargspec(self.payload)
|
|
||||||
if isinstance(name, int):
|
|
||||||
if 0 <= name < len(spec.args):
|
|
||||||
name = spec.args[name]
|
|
||||||
elif name == len(spec.args) and spec.varargs is not None:
|
|
||||||
name = spec.varargs
|
|
||||||
else:
|
|
||||||
raise IndexError('argument position is out of range')
|
|
||||||
|
|
||||||
arg_name = name
|
|
||||||
if name == spec.keywords:
|
|
||||||
position = None
|
|
||||||
arg_name = '**'
|
|
||||||
elif name == spec.varargs:
|
|
||||||
position = len(spec.args)
|
|
||||||
arg_name = '*'
|
|
||||||
elif name not in spec.args:
|
|
||||||
raise exceptions.NoParameterFoundException(
|
|
||||||
function_name=self.name or self.payload.__name__,
|
|
||||||
param_name=name)
|
|
||||||
else:
|
|
||||||
position = spec.args.index(name)
|
|
||||||
default = NO_DEFAULT
|
|
||||||
if spec.defaults is not None and name in spec.args:
|
|
||||||
index = spec.args.index(name) - len(spec.args)
|
|
||||||
if index >= -len(spec.defaults):
|
|
||||||
default = spec.defaults[index]
|
|
||||||
else:
|
|
||||||
spec = inspect.getfullargspec(self.payload)
|
spec = inspect.getfullargspec(self.payload)
|
||||||
if isinstance(name, int):
|
if isinstance(name, int):
|
||||||
if 0 <= name < len(spec.args):
|
if 0 <= name < len(spec.args):
|
||||||
@ -191,7 +158,7 @@ class FunctionDefinition(object):
|
|||||||
def insert_parameter(self, name, value_type=None, nullable=None,
|
def insert_parameter(self, name, value_type=None, nullable=None,
|
||||||
alias=None, overwrite=False):
|
alias=None, overwrite=False):
|
||||||
pd = self.set_parameter(name, value_type, nullable, alias, overwrite)
|
pd = self.set_parameter(name, value_type, nullable, alias, overwrite)
|
||||||
for p in six.itervalues(self.parameters):
|
for p in self.parameters.values():
|
||||||
if p is pd:
|
if p is pd:
|
||||||
continue
|
continue
|
||||||
if p.position is not None and p.position >= pd.position:
|
if p.position is not None and p.position >= pd.position:
|
||||||
@ -205,13 +172,13 @@ class FunctionDefinition(object):
|
|||||||
positional_fix_table = max_dst_positional_args * [0]
|
positional_fix_table = max_dst_positional_args * [0]
|
||||||
keyword_args = {}
|
keyword_args = {}
|
||||||
|
|
||||||
for p in six.itervalues(self.parameters):
|
for p in self.parameters.values():
|
||||||
if p.position is not None and isinstance(
|
if p.position is not None and isinstance(
|
||||||
p.value_type, yaqltypes.HiddenParameterType):
|
p.value_type, yaqltypes.HiddenParameterType):
|
||||||
for index in range(p.position + 1, len(positional_fix_table)):
|
for index in range(p.position + 1, len(positional_fix_table)):
|
||||||
positional_fix_table[index] += 1
|
positional_fix_table[index] += 1
|
||||||
|
|
||||||
for key, p in six.iteritems(self.parameters):
|
for key, p in self.parameters.items():
|
||||||
arg_name = p.alias or p.name
|
arg_name = p.alias or p.name
|
||||||
if p.position is not None and key != '*':
|
if p.position is not None and key != '*':
|
||||||
arg_position = p.position - positional_fix_table[p.position]
|
arg_position = p.position - positional_fix_table[p.position]
|
||||||
@ -242,7 +209,7 @@ class FunctionDefinition(object):
|
|||||||
if len(kwargs) > 0:
|
if len(kwargs) > 0:
|
||||||
if '**' in self.parameters:
|
if '**' in self.parameters:
|
||||||
argdef = self.parameters['**']
|
argdef = self.parameters['**']
|
||||||
for key in six.iterkeys(kwargs):
|
for key in kwargs:
|
||||||
keyword_args[key] = argdef
|
keyword_args[key] = argdef
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -255,7 +222,7 @@ class FunctionDefinition(object):
|
|||||||
value = positional_args[i].default
|
value = positional_args[i].default
|
||||||
if not positional_args[i].value_type.check(value, context, engine):
|
if not positional_args[i].value_type.check(value, context, engine):
|
||||||
return None
|
return None
|
||||||
for kwd in six.iterkeys(kwargs):
|
for kwd in kwargs:
|
||||||
if not keyword_args[kwd].value_type.check(
|
if not keyword_args[kwd].value_type.check(
|
||||||
kwargs[kwd], context, engine):
|
kwargs[kwd], context, engine):
|
||||||
return None
|
return None
|
||||||
@ -278,7 +245,7 @@ class FunctionDefinition(object):
|
|||||||
kwargs = kwargs.copy()
|
kwargs = kwargs.copy()
|
||||||
kwargs = dict(kwargs)
|
kwargs = dict(kwargs)
|
||||||
positional = 0
|
positional = 0
|
||||||
for arg_name, p in six.iteritems(self.parameters):
|
for arg_name, p in self.parameters.items():
|
||||||
if p.position is not None and arg_name != '*':
|
if p.position is not None and arg_name != '*':
|
||||||
positional += 1
|
positional += 1
|
||||||
|
|
||||||
@ -286,13 +253,13 @@ class FunctionDefinition(object):
|
|||||||
positional_fix_table = positional * [0]
|
positional_fix_table = positional * [0]
|
||||||
keyword_args = {}
|
keyword_args = {}
|
||||||
|
|
||||||
for p in six.itervalues(self.parameters):
|
for p in self.parameters.values():
|
||||||
if p.position is not None and isinstance(
|
if p.position is not None and isinstance(
|
||||||
p.value_type, yaqltypes.HiddenParameterType):
|
p.value_type, yaqltypes.HiddenParameterType):
|
||||||
for index in range(p.position + 1, positional):
|
for index in range(p.position + 1, positional):
|
||||||
positional_fix_table[index] += 1
|
positional_fix_table[index] += 1
|
||||||
|
|
||||||
for key, p in six.iteritems(self.parameters):
|
for key, p in self.parameters.items():
|
||||||
arg_name = p.alias or p.name
|
arg_name = p.alias or p.name
|
||||||
if p.position is not None and key != '*':
|
if p.position is not None and key != '*':
|
||||||
if isinstance(p.value_type, yaqltypes.HiddenParameterType):
|
if isinstance(p.value_type, yaqltypes.HiddenParameterType):
|
||||||
@ -332,7 +299,7 @@ class FunctionDefinition(object):
|
|||||||
if len(kwargs) > 0:
|
if len(kwargs) > 0:
|
||||||
if '**' in self.parameters:
|
if '**' in self.parameters:
|
||||||
argdef = self.parameters['**']
|
argdef = self.parameters['**']
|
||||||
for key, value in six.iteritems(kwargs):
|
for key, value in kwargs.items():
|
||||||
keyword_args[key] = checked(value, argdef)
|
keyword_args[key] = checked(value, argdef)
|
||||||
else:
|
else:
|
||||||
raise exceptions.ArgumentException('**')
|
raise exceptions.ArgumentException('**')
|
||||||
@ -343,7 +310,7 @@ class FunctionDefinition(object):
|
|||||||
*tuple(map(lambda t: t(new_context),
|
*tuple(map(lambda t: t(new_context),
|
||||||
positional_args)),
|
positional_args)),
|
||||||
**dict(map(lambda t: (t[0], t[1](new_context)),
|
**dict(map(lambda t: (t[0], t[1](new_context)),
|
||||||
six.iteritems(keyword_args)))
|
keyword_args.items()))
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -352,7 +319,7 @@ class FunctionDefinition(object):
|
|||||||
def is_valid_method(self):
|
def is_valid_method(self):
|
||||||
min_position = len(self.parameters)
|
min_position = len(self.parameters)
|
||||||
min_arg = None
|
min_arg = None
|
||||||
for p in six.itervalues(self.parameters):
|
for p in self.parameters.values():
|
||||||
if p.position is not None and p.position < min_position and \
|
if p.position is not None and p.position < min_position and \
|
||||||
not isinstance(p.value_type,
|
not isinstance(p.value_type,
|
||||||
yaqltypes.HiddenParameterType):
|
yaqltypes.HiddenParameterType):
|
||||||
@ -407,16 +374,6 @@ def get_function_definition(func, name=None, function=None, method=None,
|
|||||||
if parameter_type_func is None:
|
if parameter_type_func is None:
|
||||||
parameter_type_func = _infer_parameter_type
|
parameter_type_func = _infer_parameter_type
|
||||||
fd = _get_function_definition(func).clone()
|
fd = _get_function_definition(func).clone()
|
||||||
if six.PY2:
|
|
||||||
spec = inspect.getargspec(func)
|
|
||||||
for arg in spec.args:
|
|
||||||
if arg not in fd.parameters:
|
|
||||||
fd.set_parameter(arg, parameter_type_func(arg))
|
|
||||||
if spec.varargs and '*' not in fd.parameters:
|
|
||||||
fd.set_parameter(spec.varargs, parameter_type_func(spec.varargs))
|
|
||||||
if spec.keywords and '**' not in fd.parameters:
|
|
||||||
fd.set_parameter(spec.keywords, parameter_type_func(spec.keywords))
|
|
||||||
else:
|
|
||||||
spec = inspect.getfullargspec(func)
|
spec = inspect.getfullargspec(func)
|
||||||
for arg in spec.args + spec.kwonlyargs:
|
for arg in spec.args + spec.kwonlyargs:
|
||||||
if arg not in fd.parameters:
|
if arg not in fd.parameters:
|
||||||
@ -438,7 +395,7 @@ def get_function_definition(func, name=None, function=None, method=None,
|
|||||||
if method is not None:
|
if method is not None:
|
||||||
fd.is_method = method
|
fd.is_method = method
|
||||||
if convention:
|
if convention:
|
||||||
for p in six.itervalues(fd.parameters):
|
for p in fd.parameters.values():
|
||||||
if p.alias is None:
|
if p.alias is None:
|
||||||
p.alias = convert_parameter_name(p.name, convention)
|
p.alias = convert_parameter_name(p.name, convention)
|
||||||
return fd
|
return fd
|
||||||
|
@ -16,8 +16,6 @@ import collections
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import lexer
|
from yaql.language import lexer
|
||||||
|
|
||||||
@ -38,13 +36,15 @@ def is_iterator(obj):
|
|||||||
|
|
||||||
|
|
||||||
def is_iterable(obj):
|
def is_iterable(obj):
|
||||||
return isinstance(obj, collections.Iterable) and not isinstance(
|
return (
|
||||||
obj, six.string_types + (MappingType,))
|
isinstance(obj, collections.Iterable) and
|
||||||
|
not isinstance(obj, (str, MappingType))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_sequence(obj):
|
def is_sequence(obj):
|
||||||
return isinstance(obj, collections.Sequence) and not isinstance(
|
return isinstance(obj, collections.Sequence) and not isinstance(
|
||||||
obj, six.string_types)
|
obj, str)
|
||||||
|
|
||||||
|
|
||||||
def is_mutable(obj):
|
def is_mutable(obj):
|
||||||
@ -67,17 +67,17 @@ QueueType = collections.deque
|
|||||||
def convert_input_data(obj, rec=None):
|
def convert_input_data(obj, rec=None):
|
||||||
if rec is None:
|
if rec is None:
|
||||||
rec = convert_input_data
|
rec = convert_input_data
|
||||||
if isinstance(obj, six.string_types):
|
if isinstance(obj, str):
|
||||||
return obj if isinstance(obj, six.text_type) else six.text_type(obj)
|
return obj if isinstance(obj, str) else str(obj)
|
||||||
elif isinstance(obj, SequenceType):
|
elif isinstance(obj, SequenceType):
|
||||||
return tuple(rec(t, rec) for t in obj)
|
return tuple(rec(t, rec) for t in obj)
|
||||||
elif isinstance(obj, MappingType):
|
elif isinstance(obj, MappingType):
|
||||||
return FrozenDict((rec(key, rec), rec(value, rec))
|
return FrozenDict((rec(key, rec), rec(value, rec))
|
||||||
for key, value in six.iteritems(obj))
|
for key, value in obj.items())
|
||||||
elif isinstance(obj, MutableSetType):
|
elif isinstance(obj, MutableSetType):
|
||||||
return frozenset(rec(t, rec) for t in obj)
|
return frozenset(rec(t, rec) for t in obj)
|
||||||
elif isinstance(obj, IterableType):
|
elif isinstance(obj, IterableType):
|
||||||
return six.moves.map(lambda v: rec(v, rec), obj)
|
return map(lambda v: rec(v, rec), obj)
|
||||||
else:
|
else:
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ def convert_output_data(obj, limit_func, engine, rec=None):
|
|||||||
rec = convert_output_data
|
rec = convert_output_data
|
||||||
if isinstance(obj, collections.Mapping):
|
if isinstance(obj, collections.Mapping):
|
||||||
result = {}
|
result = {}
|
||||||
for key, value in limit_func(six.iteritems(obj)):
|
for key, value in limit_func(obj.items()):
|
||||||
result[rec(key, limit_func, engine, rec)] = rec(
|
result[rec(key, limit_func, engine, rec)] = rec(
|
||||||
value, limit_func, engine, rec)
|
value, limit_func, engine, rec)
|
||||||
return result
|
return result
|
||||||
@ -139,7 +139,7 @@ class FrozenDict(collections.Mapping):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
if self._hash is None:
|
if self._hash is None:
|
||||||
self._hash = 0
|
self._hash = 0
|
||||||
for pair in six.iteritems(self):
|
for pair in self.items():
|
||||||
self._hash ^= hash(pair)
|
self._hash ^= hash(pair)
|
||||||
return self._hash
|
return self._hash
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ def memorize(collection, engine):
|
|||||||
|
|
||||||
yielded = []
|
yielded = []
|
||||||
|
|
||||||
class RememberingIterator(six.Iterator):
|
class RememberingIterator:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.seq = iter(collection)
|
self.seq = iter(collection)
|
||||||
self.index = 0
|
self.index = 0
|
||||||
|
@ -17,7 +17,6 @@ import collections
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from dateutil import tz
|
from dateutil import tz
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import expressions
|
from yaql.language import expressions
|
||||||
@ -25,8 +24,7 @@ from yaql.language import utils
|
|||||||
from yaql import yaql_interface
|
from yaql import yaql_interface
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class HiddenParameterType(metaclass=abc.ABCMeta):
|
||||||
class HiddenParameterType(object):
|
|
||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
||||||
@ -34,13 +32,11 @@ class HiddenParameterType(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class LazyParameterType(metaclass=abc.ABCMeta):
|
||||||
class LazyParameterType(object):
|
|
||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class SmartType(metaclass=abc.ABCMeta):
|
||||||
class SmartType(object):
|
|
||||||
__slots__ = ('nullable',)
|
__slots__ = ('nullable',)
|
||||||
|
|
||||||
def __init__(self, nullable):
|
def __init__(self, nullable):
|
||||||
@ -149,13 +145,13 @@ class String(PythonType):
|
|||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
|
|
||||||
def __init__(self, nullable=False):
|
def __init__(self, nullable=False):
|
||||||
super(String, self).__init__(six.string_types, nullable=nullable)
|
super(String, self).__init__(str, nullable=nullable)
|
||||||
|
|
||||||
def convert(self, value, receiver, context, function_spec, engine,
|
def convert(self, value, receiver, context, function_spec, engine,
|
||||||
*args, **kwargs):
|
*args, **kwargs):
|
||||||
value = super(String, self).convert(
|
value = super(String, self).convert(
|
||||||
value, receiver, context, function_spec, engine, *args, **kwargs)
|
value, receiver, context, function_spec, engine, *args, **kwargs)
|
||||||
return None if value is None else six.text_type(value)
|
return None if value is None else str(value)
|
||||||
|
|
||||||
|
|
||||||
class Integer(PythonType):
|
class Integer(PythonType):
|
||||||
@ -163,7 +159,7 @@ class Integer(PythonType):
|
|||||||
|
|
||||||
def __init__(self, nullable=False):
|
def __init__(self, nullable=False):
|
||||||
super(Integer, self).__init__(
|
super(Integer, self).__init__(
|
||||||
six.integer_types, nullable=nullable,
|
int, nullable=nullable,
|
||||||
validators=[lambda t: not isinstance(t, bool)])
|
validators=[lambda t: not isinstance(t, bool)])
|
||||||
|
|
||||||
|
|
||||||
@ -189,9 +185,9 @@ class Iterable(PythonType):
|
|||||||
|
|
||||||
def __init__(self, validators=None, nullable=False):
|
def __init__(self, validators=None, nullable=False):
|
||||||
super(Iterable, self).__init__(
|
super(Iterable, self).__init__(
|
||||||
collections.Iterable, nullable, [
|
collections.Iterable, nullable,
|
||||||
lambda t: not isinstance(t, six.string_types + (
|
[lambda t: not isinstance(t, (str, utils.MappingType))] + (
|
||||||
utils.MappingType,))] + (validators or []))
|
validators or []))
|
||||||
|
|
||||||
def check(self, value, context, engine, *args, **kwargs):
|
def check(self, value, context, engine, *args, **kwargs):
|
||||||
if isinstance(value, utils.MappingType) and engine.options.get(
|
if isinstance(value, utils.MappingType) and engine.options.get(
|
||||||
@ -222,7 +218,7 @@ class Sequence(PythonType):
|
|||||||
def __init__(self, validators=None, nullable=False):
|
def __init__(self, validators=None, nullable=False):
|
||||||
super(Sequence, self).__init__(
|
super(Sequence, self).__init__(
|
||||||
collections.Sequence, nullable, [
|
collections.Sequence, nullable, [
|
||||||
lambda t: not isinstance(t, six.string_types + (dict,))] + (
|
lambda t: not isinstance(t, (str, dict))] + (
|
||||||
validators or []))
|
validators or []))
|
||||||
|
|
||||||
|
|
||||||
@ -231,7 +227,7 @@ class Number(PythonType):
|
|||||||
|
|
||||||
def __init__(self, nullable=False):
|
def __init__(self, nullable=False):
|
||||||
super(Number, self).__init__(
|
super(Number, self).__init__(
|
||||||
six.integer_types + (float,), nullable,
|
(int, float), nullable,
|
||||||
validators=[lambda t: not isinstance(t, bool)])
|
validators=[lambda t: not isinstance(t, bool)])
|
||||||
|
|
||||||
|
|
||||||
@ -260,7 +256,7 @@ class Lambda(LazyParameterType, SmartType):
|
|||||||
self._publish_params(context, args, kwargs)
|
self._publish_params(context, args, kwargs)
|
||||||
if isinstance(value, expressions.Expression):
|
if isinstance(value, expressions.Expression):
|
||||||
result = value(receiver, context, engine)
|
result = value(receiver, context, engine)
|
||||||
elif six.callable(value):
|
elif callable(value):
|
||||||
result = value(*args, **kwargs)
|
result = value(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
result = value
|
result = value
|
||||||
@ -273,7 +269,7 @@ class Lambda(LazyParameterType, SmartType):
|
|||||||
*convert_args, **convert_kwargs)
|
*convert_args, **convert_kwargs)
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
elif six.callable(value) and hasattr(value, '__unwrapped__'):
|
elif callable(value) and hasattr(value, '__unwrapped__'):
|
||||||
value = value.__unwrapped__
|
value = value.__unwrapped__
|
||||||
|
|
||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
@ -318,7 +314,7 @@ class Super(HiddenParameterType, SmartType):
|
|||||||
|
|
||||||
def convert(self, value, receiver, context, function_spec, engine,
|
def convert(self, value, receiver, context, function_spec, engine,
|
||||||
*convert_args, **convert_kwargs):
|
*convert_args, **convert_kwargs):
|
||||||
if six.callable(value) and hasattr(value, '__unwrapped__'):
|
if callable(value) and hasattr(value, '__unwrapped__'):
|
||||||
value = value.__unwrapped__
|
value = value.__unwrapped__
|
||||||
|
|
||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
@ -377,7 +373,7 @@ class Delegate(HiddenParameterType, SmartType):
|
|||||||
|
|
||||||
def convert(self, value, receiver, context, function_spec, engine,
|
def convert(self, value, receiver, context, function_spec, engine,
|
||||||
*convert_args, **convert_kwargs):
|
*convert_args, **convert_kwargs):
|
||||||
if six.callable(value) and hasattr(value, '__unwrapped__'):
|
if callable(value) and hasattr(value, '__unwrapped__'):
|
||||||
value = value.__unwrapped__
|
value = value.__unwrapped__
|
||||||
|
|
||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
@ -485,7 +481,7 @@ class StringConstant(Constant):
|
|||||||
def check(self, value, context, *args, **kwargs):
|
def check(self, value, context, *args, **kwargs):
|
||||||
return super(StringConstant, self).check(
|
return super(StringConstant, self).check(
|
||||||
value, context, *args, **kwargs) and (
|
value, context, *args, **kwargs) and (
|
||||||
value is None or isinstance(value.value, six.string_types))
|
value is None or isinstance(value.value, str))
|
||||||
|
|
||||||
|
|
||||||
class Keyword(Constant):
|
class Keyword(Constant):
|
||||||
@ -519,13 +515,12 @@ class NumericConstant(Constant):
|
|||||||
def check(self, value, context, *args, **kwargs):
|
def check(self, value, context, *args, **kwargs):
|
||||||
return super(NumericConstant, self).check(
|
return super(NumericConstant, self).check(
|
||||||
value, context, *args, **kwargs) and (
|
value, context, *args, **kwargs) and (
|
||||||
value is None or isinstance(
|
value is None or
|
||||||
value.value, six.integer_types + (float,)) and
|
isinstance(value.value, (int, float)) and
|
||||||
type(value.value) is not bool)
|
type(value.value) is not bool)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class SmartTypeAggregation(SmartType, metaclass=abc.ABCMeta):
|
||||||
class SmartTypeAggregation(SmartType):
|
|
||||||
__slots__ = ('types',)
|
__slots__ = ('types',)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -17,8 +17,6 @@ Functions that produce or consume finite collections - lists, dicts and sets.
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
@ -328,7 +326,7 @@ def dict_set(engine, d, key, value):
|
|||||||
{"a": 1, "b": 3}
|
{"a": 1, "b": 3}
|
||||||
"""
|
"""
|
||||||
utils.limit_memory_usage(engine, (1, d), (1, key), (1, value))
|
utils.limit_memory_usage(engine, (1, d), (1, key), (1, value))
|
||||||
return utils.FrozenDict(itertools.chain(six.iteritems(d), ((key, value),)))
|
return utils.FrozenDict(itertools.chain(d.items(), ((key, value),)))
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('d', utils.MappingType, alias='dict')
|
@specs.parameter('d', utils.MappingType, alias='dict')
|
||||||
@ -354,8 +352,7 @@ def dict_set_many(engine, d, replacements):
|
|||||||
{"a": 1, "c": 4, "b": 3}
|
{"a": 1, "c": 4, "b": 3}
|
||||||
"""
|
"""
|
||||||
utils.limit_memory_usage(engine, (1, d), (1, replacements))
|
utils.limit_memory_usage(engine, (1, d), (1, replacements))
|
||||||
return utils.FrozenDict(itertools.chain(
|
return utils.FrozenDict(itertools.chain(d.items(), replacements.items()))
|
||||||
six.iteritems(d), six.iteritems(replacements)))
|
|
||||||
|
|
||||||
|
|
||||||
@specs.no_kwargs
|
@specs.no_kwargs
|
||||||
@ -382,7 +379,7 @@ def dict_set_many_inline(engine, d, *args):
|
|||||||
"""
|
"""
|
||||||
utils.limit_memory_usage(engine, (1, d), *((1, arg) for arg in args))
|
utils.limit_memory_usage(engine, (1, d), *((1, arg) for arg in args))
|
||||||
return utils.FrozenDict(itertools.chain(
|
return utils.FrozenDict(itertools.chain(
|
||||||
six.iteritems(d), ((t.source, t.destination) for t in args)))
|
d.items(), ((t.source, t.destination) for t in args)))
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('d', utils.MappingType, alias='dict')
|
@specs.parameter('d', utils.MappingType, alias='dict')
|
||||||
@ -403,7 +400,7 @@ def dict_keys(d):
|
|||||||
yaql> {"a" => 1, "b" => 2}.keys()
|
yaql> {"a" => 1, "b" => 2}.keys()
|
||||||
["a", "b"]
|
["a", "b"]
|
||||||
"""
|
"""
|
||||||
return six.iterkeys(d)
|
return d.keys()
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('d', utils.MappingType, alias='dict')
|
@specs.parameter('d', utils.MappingType, alias='dict')
|
||||||
@ -424,7 +421,7 @@ def dict_values(d):
|
|||||||
yaql> {"a" => 1, "b" => 2}.values()
|
yaql> {"a" => 1, "b" => 2}.values()
|
||||||
[1, 2]
|
[1, 2]
|
||||||
"""
|
"""
|
||||||
return six.itervalues(d)
|
return d.values()
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('d', utils.MappingType, alias='dict')
|
@specs.parameter('d', utils.MappingType, alias='dict')
|
||||||
@ -445,7 +442,7 @@ def dict_items(d):
|
|||||||
yaql> {"a" => 1, "b" => 2}.items()
|
yaql> {"a" => 1, "b" => 2}.items()
|
||||||
[["a", 1], ["b", 2]]
|
[["a", 1], ["b", 2]]
|
||||||
"""
|
"""
|
||||||
return six.iteritems(d)
|
return d.items()
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('lst', yaqltypes.Sequence(), alias='list')
|
@specs.parameter('lst', yaqltypes.Sequence(), alias='list')
|
||||||
@ -563,7 +560,7 @@ def contains_value(d, value):
|
|||||||
yaql> {"a" => 1, "b" => 2}.containsValue(2)
|
yaql> {"a" => 1, "b" => 2}.containsValue(2)
|
||||||
true
|
true
|
||||||
"""
|
"""
|
||||||
return value in six.itervalues(d)
|
return value in d.values()
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('left', yaqltypes.Iterable())
|
@specs.parameter('left', yaqltypes.Iterable())
|
||||||
|
@ -19,8 +19,6 @@ Examples are provided with CLI started with legacy mode.
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import contexts
|
from yaql.language import contexts
|
||||||
from yaql.language import expressions
|
from yaql.language import expressions
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
@ -124,7 +122,7 @@ def indexer(collection, index_expression):
|
|||||||
index = index_expression()
|
index = index_expression()
|
||||||
if isinstance(index, int) and not isinstance(index, bool):
|
if isinstance(index, int) and not isinstance(index, bool):
|
||||||
return collection[index]
|
return collection[index]
|
||||||
return six.moves.filter(index_expression, collection)
|
return filter(index_expression, collection)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('start', int)
|
@specs.parameter('start', int)
|
||||||
@ -153,7 +151,7 @@ def range_(start, stop=None):
|
|||||||
if stop is None:
|
if stop is None:
|
||||||
return itertools.count(start)
|
return itertools.count(start)
|
||||||
else:
|
else:
|
||||||
return six.moves.range(start, stop)
|
return range(start, stop)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('conditions', yaqltypes.Lambda(with_context=True))
|
@specs.parameter('conditions', yaqltypes.Lambda(with_context=True))
|
||||||
|
@ -16,8 +16,6 @@ The Math module describes implemented math operations on numbers.
|
|||||||
"""
|
"""
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
|
|
||||||
@ -113,8 +111,7 @@ def division(left, right):
|
|||||||
yaql> 3.0 / 2
|
yaql> 3.0 / 2
|
||||||
1.5
|
1.5
|
||||||
"""
|
"""
|
||||||
if isinstance(left, six.integer_types) and isinstance(
|
if isinstance(left, int) and isinstance(right, int):
|
||||||
right, six.integer_types):
|
|
||||||
return left // right
|
return left // right
|
||||||
return left / right
|
return left / right
|
||||||
|
|
||||||
@ -654,7 +651,7 @@ def is_integer(value):
|
|||||||
yaql> isInteger(12)
|
yaql> isInteger(12)
|
||||||
true
|
true
|
||||||
"""
|
"""
|
||||||
return isinstance(value, six.integer_types) and not isinstance(value, bool)
|
return isinstance(value, int) and not isinstance(value, bool)
|
||||||
|
|
||||||
|
|
||||||
def is_number(value):
|
def is_number(value):
|
||||||
@ -674,8 +671,7 @@ def is_number(value):
|
|||||||
yaql> isNumber(12)
|
yaql> isNumber(12)
|
||||||
true
|
true
|
||||||
"""
|
"""
|
||||||
return (isinstance(value, six.integer_types + (float,))
|
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
||||||
and not isinstance(value, bool))
|
|
||||||
|
|
||||||
|
|
||||||
def register(context):
|
def register(context):
|
||||||
|
@ -19,10 +19,8 @@ Queries module.
|
|||||||
# yaql.standard_library.collections
|
# yaql.standard_library.collections
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
import sys
|
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
@ -110,7 +108,7 @@ def where(collection, predicate):
|
|||||||
yaql> [1, 2, 3, 4, 5].where($ > 3)
|
yaql> [1, 2, 3, 4, 5].where($ > 3)
|
||||||
[4, 5]
|
[4, 5]
|
||||||
"""
|
"""
|
||||||
return six.moves.filter(predicate, collection)
|
return filter(predicate, collection)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('collection', yaqltypes.Iterable())
|
@specs.parameter('collection', yaqltypes.Iterable())
|
||||||
@ -136,7 +134,7 @@ def select(collection, selector):
|
|||||||
yaql> [{'a'=> 2}, {'a'=> 4}].select($.a)
|
yaql> [{'a'=> 2}, {'a'=> 4}].select($.a)
|
||||||
[2, 4]
|
[2, 4]
|
||||||
"""
|
"""
|
||||||
return six.moves.map(selector, collection)
|
return map(selector, collection)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('collection', yaqltypes.Iterable())
|
@specs.parameter('collection', yaqltypes.Iterable())
|
||||||
@ -161,8 +159,7 @@ def collection_attribution(collection, attribute, operator):
|
|||||||
yaql> [{"a" => 1}, {"a" => 2, "b" => 3}].a
|
yaql> [{"a" => 1}, {"a" => 2, "b" => 3}].a
|
||||||
[1, 2]
|
[1, 2]
|
||||||
"""
|
"""
|
||||||
return six.moves.map(
|
return map(lambda t: operator(t, attribute), collection)
|
||||||
lambda t: operator(t, attribute), collection)
|
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('collection', yaqltypes.Iterable())
|
@specs.parameter('collection', yaqltypes.Iterable())
|
||||||
@ -554,7 +551,7 @@ def first(collection, default=utils.NO_VALUE):
|
|||||||
3
|
3
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return six.next(iter(collection))
|
return next(iter(collection))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
if default is utils.NO_VALUE:
|
if default is utils.NO_VALUE:
|
||||||
raise
|
raise
|
||||||
@ -582,9 +579,9 @@ def single(collection):
|
|||||||
Execution exception: Collection contains more than one item
|
Execution exception: Collection contains more than one item
|
||||||
"""
|
"""
|
||||||
it = iter(collection)
|
it = iter(collection)
|
||||||
result = six.next(it)
|
result = next(it)
|
||||||
try:
|
try:
|
||||||
six.next(it)
|
next(it)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return result
|
return result
|
||||||
raise StopIteration('Collection contains more than one item')
|
raise StopIteration('Collection contains more than one item')
|
||||||
@ -679,7 +676,7 @@ def range_(stop):
|
|||||||
yaql> range(3)
|
yaql> range(3)
|
||||||
[0, 1, 2]
|
[0, 1, 2]
|
||||||
"""
|
"""
|
||||||
return iter(six.moves.range(stop))
|
return iter(range(stop))
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('start', int)
|
@specs.parameter('start', int)
|
||||||
@ -708,7 +705,7 @@ def range__(start, stop, step=1):
|
|||||||
yaql> range(4, 1, -1)
|
yaql> range(4, 1, -1)
|
||||||
[4, 3, 2]
|
[4, 3, 2]
|
||||||
"""
|
"""
|
||||||
return iter(six.moves.range(start, stop, step))
|
return iter(range(start, stop, step))
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('start', int)
|
@specs.parameter('start', int)
|
||||||
@ -877,16 +874,20 @@ class GroupAggregator(object):
|
|||||||
key, value_list = group_item
|
key, value_list = group_item
|
||||||
try:
|
try:
|
||||||
result = self.aggregator(value_list)
|
result = self.aggregator(value_list)
|
||||||
except (exceptions.NoMatchingMethodException,
|
except (
|
||||||
|
exceptions.NoMatchingMethodException,
|
||||||
exceptions.NoMatchingFunctionException,
|
exceptions.NoMatchingFunctionException,
|
||||||
IndexError):
|
IndexError,
|
||||||
self._failure_info = sys.exc_info()
|
) as exc:
|
||||||
|
self._failure_info = exc
|
||||||
else:
|
else:
|
||||||
if not (len(value_list) == 2 and
|
if not (
|
||||||
|
len(value_list) == 2 and
|
||||||
isinstance(result, collections.Sequence) and
|
isinstance(result, collections.Sequence) and
|
||||||
not isinstance(result, six.string_types) and
|
not isinstance(result, str) and
|
||||||
len(result) == 2 and
|
len(result) == 2 and
|
||||||
result[0] == value_list[0]):
|
result[0] == value_list[0]
|
||||||
|
):
|
||||||
# We are not dealing with (correct) version 1.1.1 syntax,
|
# We are not dealing with (correct) version 1.1.1 syntax,
|
||||||
# so don't bother trying to fall back if there's an error
|
# so don't bother trying to fall back if there's an error
|
||||||
# with a later group.
|
# with a later group.
|
||||||
@ -905,7 +906,7 @@ class GroupAggregator(object):
|
|||||||
|
|
||||||
# If we are unable to successfully fall back, re-raise the first
|
# If we are unable to successfully fall back, re-raise the first
|
||||||
# exception encountered to help the user debug in the new style.
|
# exception encountered to help the user debug in the new style.
|
||||||
six.reraise(*self._failure_info)
|
raise self._failure_info
|
||||||
|
|
||||||
|
|
||||||
def group_by_function(allow_aggregator_fallback):
|
def group_by_function(allow_aggregator_fallback):
|
||||||
@ -952,7 +953,7 @@ def group_by_function(allow_aggregator_fallback):
|
|||||||
value = t if value_selector is None else value_selector(t)
|
value = t if value_selector is None else value_selector(t)
|
||||||
groups.setdefault(key_selector(t), []).append(value)
|
groups.setdefault(key_selector(t), []).append(value)
|
||||||
utils.limit_memory_usage(engine, (1, groups))
|
utils.limit_memory_usage(engine, (1, groups))
|
||||||
return select(six.iteritems(groups), new_aggregator)
|
return select(groups.items(), new_aggregator)
|
||||||
|
|
||||||
return group_by
|
return group_by
|
||||||
|
|
||||||
@ -978,7 +979,7 @@ def zip_(*collections):
|
|||||||
yaql> [1, 2, 3].zip([4, 5], [6, 7])
|
yaql> [1, 2, 3].zip([4, 5], [6, 7])
|
||||||
[[1, 4, 6], [2, 5, 7]]
|
[[1, 4, 6], [2, 5, 7]]
|
||||||
"""
|
"""
|
||||||
return six.moves.zip(*collections)
|
return zip(*collections)
|
||||||
|
|
||||||
|
|
||||||
@specs.method
|
@specs.method
|
||||||
@ -1008,7 +1009,7 @@ def zip_longest(*collections, **kwargs):
|
|||||||
yaql> [1, 2, 3].zipLongest([4, 5], default => 100)
|
yaql> [1, 2, 3].zipLongest([4, 5], default => 100)
|
||||||
[[1, 4], [2, 5], [3, 100]]
|
[[1, 4], [2, 5], [3, 100]]
|
||||||
"""
|
"""
|
||||||
return six.moves.zip_longest(
|
return itertools.zip_longest(
|
||||||
*collections, fillvalue=kwargs.pop('default', None))
|
*collections, fillvalue=kwargs.pop('default', None))
|
||||||
|
|
||||||
|
|
||||||
@ -1424,9 +1425,9 @@ def aggregate(collection, selector, seed=utils.NO_VALUE):
|
|||||||
1
|
1
|
||||||
"""
|
"""
|
||||||
if seed is utils.NO_VALUE:
|
if seed is utils.NO_VALUE:
|
||||||
return six.moves.reduce(selector, collection)
|
return functools.reduce(selector, collection)
|
||||||
else:
|
else:
|
||||||
return six.moves.reduce(selector, collection, seed)
|
return functools.reduce(selector, collection, seed)
|
||||||
|
|
||||||
|
|
||||||
@specs.method
|
@specs.method
|
||||||
@ -1452,7 +1453,7 @@ def reverse(collection, to_list):
|
|||||||
|
|
||||||
def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
|
def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
|
||||||
result = {}
|
result = {}
|
||||||
for key, value1 in six.iteritems(dict1):
|
for key, value1 in dict1.items():
|
||||||
result[key] = value1
|
result[key] = value1
|
||||||
if key in dict2:
|
if key in dict2:
|
||||||
value2 = dict2[key]
|
value2 = dict2[key]
|
||||||
@ -1473,7 +1474,7 @@ def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
|
|||||||
else:
|
else:
|
||||||
result[key] = item_merger(value1, value2)
|
result[key] = item_merger(value1, value2)
|
||||||
|
|
||||||
for key2, value2 in six.iteritems(dict2):
|
for key2, value2 in dict2.items():
|
||||||
if key2 not in result:
|
if key2 not in result:
|
||||||
result[key2] = value2
|
result[key2] = value2
|
||||||
return result
|
return result
|
||||||
|
@ -17,8 +17,6 @@ The module contains functions for regular expressions.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
|
|
||||||
@ -226,7 +224,7 @@ def _publish_match(context, match):
|
|||||||
}
|
}
|
||||||
context['$' + str(i + 1)] = rec
|
context['$' + str(i + 1)] = rec
|
||||||
|
|
||||||
for key, value, in six.itervalues(match.groupdict()):
|
for key, value, in match.groupdict().values():
|
||||||
rec = {
|
rec = {
|
||||||
'value': value,
|
'value': value,
|
||||||
'start': match.start(value),
|
'start': match.start(value),
|
||||||
|
@ -17,8 +17,6 @@ The module describes which operations can be done with strings in YAQL.
|
|||||||
|
|
||||||
import string as string_module
|
import string as string_module
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
@ -299,7 +297,7 @@ def join(sequence, separator, str_delegate):
|
|||||||
yaql> ["abc", "de", "f"].join("|")
|
yaql> ["abc", "de", "f"].join("|")
|
||||||
"abc|de|f"
|
"abc|de|f"
|
||||||
"""
|
"""
|
||||||
return separator.join(six.moves.map(str_delegate, sequence))
|
return separator.join(map(str_delegate, sequence))
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('sequence', yaqltypes.Iterable())
|
@specs.parameter('sequence', yaqltypes.Iterable())
|
||||||
@ -351,7 +349,7 @@ def str_(value):
|
|||||||
elif value is False:
|
elif value is False:
|
||||||
return 'false'
|
return 'false'
|
||||||
else:
|
else:
|
||||||
return six.text_type(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('string', yaqltypes.String())
|
@specs.parameter('string', yaqltypes.String())
|
||||||
@ -561,7 +559,7 @@ def replace_with_dict(string, str_func, replacements, count=-1):
|
|||||||
yaql> "abc ab abc".replace({ab => yy, abc => xx}, 1)
|
yaql> "abc ab abc".replace({ab => yy, abc => xx}, 1)
|
||||||
"yyc ab xx"
|
"yyc ab xx"
|
||||||
"""
|
"""
|
||||||
for key, value in six.iteritems(replacements):
|
for key, value in replacements.items():
|
||||||
string = string.replace(str_func(key), str_func(value), count)
|
string = string.replace(str_func(key), str_func(value), count)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
@ -955,7 +953,7 @@ def is_string(arg):
|
|||||||
yaql> isString(1)
|
yaql> isString(1)
|
||||||
false
|
false
|
||||||
"""
|
"""
|
||||||
return isinstance(arg, six.string_types)
|
return isinstance(arg, str)
|
||||||
|
|
||||||
|
|
||||||
@specs.parameter('string', yaqltypes.String())
|
@specs.parameter('string', yaqltypes.String())
|
||||||
|
@ -17,8 +17,6 @@ The module describes main system functions for working with objects.
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import contexts
|
from yaql.language import contexts
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
@ -175,7 +173,7 @@ def let(__context__, *args, **kwargs):
|
|||||||
for i, value in enumerate(args, 1):
|
for i, value in enumerate(args, 1):
|
||||||
__context__[str(i)] = value
|
__context__[str(i)] = value
|
||||||
|
|
||||||
for key, value in six.iteritems(kwargs):
|
for key, value in kwargs.items():
|
||||||
__context__[key] = value
|
__context__[key] = value
|
||||||
return __context__
|
return __context__
|
||||||
|
|
||||||
@ -267,7 +265,7 @@ def assert__(engine, obj, condition, message=u'Assertion failed'):
|
|||||||
|
|
||||||
@specs.name('#call')
|
@specs.name('#call')
|
||||||
@specs.parameter('callable_', yaqltypes.PythonType(
|
@specs.parameter('callable_', yaqltypes.PythonType(
|
||||||
object, False, validators=(six.callable,)))
|
object, False, validators=(callable,)))
|
||||||
def call(callable_, *args, **kwargs):
|
def call(callable_, *args, **kwargs):
|
||||||
""":yaql:call
|
""":yaql:call
|
||||||
|
|
||||||
|
@ -47,8 +47,6 @@ This module provides implemented operators on Yaqlized objects.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import expressions
|
from yaql.language import expressions
|
||||||
from yaql.language import runner
|
from yaql.language import runner
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
@ -83,7 +81,7 @@ def _match_name_to_entry(name, entry):
|
|||||||
return True
|
return True
|
||||||
elif isinstance(entry, REGEX_TYPE):
|
elif isinstance(entry, REGEX_TYPE):
|
||||||
return entry.search(name) is not None
|
return entry.search(name) is not None
|
||||||
elif six.callable(entry):
|
elif callable(entry):
|
||||||
return entry(name)
|
return entry(name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -143,7 +141,7 @@ def op_dot(receiver, expr, context, engine):
|
|||||||
mappings = _remap_name(expr.name, settings)
|
mappings = _remap_name(expr.name, settings)
|
||||||
|
|
||||||
_validate_name(expr.name, settings)
|
_validate_name(expr.name, settings)
|
||||||
if not isinstance(mappings, six.string_types):
|
if not isinstance(mappings, str):
|
||||||
name = mappings[0]
|
name = mappings[0]
|
||||||
if len(mappings) > 0:
|
if len(mappings) > 0:
|
||||||
arg_mappings = mappings[1]
|
arg_mappings = mappings[1]
|
||||||
@ -156,7 +154,7 @@ def op_dot(receiver, expr, context, engine):
|
|||||||
func = getattr(receiver, name)
|
func = getattr(receiver, name)
|
||||||
args, kwargs = runner.translate_args(False, expr.args, {})
|
args, kwargs = runner.translate_args(False, expr.args, {})
|
||||||
args = tuple(arg(utils.NO_VALUE, context, engine) for arg in args)
|
args = tuple(arg(utils.NO_VALUE, context, engine) for arg in args)
|
||||||
for key, value in six.iteritems(kwargs):
|
for key, value in kwargs.items():
|
||||||
kwargs[arg_mappings.get(key, key)] = value(
|
kwargs[arg_mappings.get(key, key)] = value(
|
||||||
utils.NO_VALUE, context, engine)
|
utils.NO_VALUE, context, engine)
|
||||||
res = func(*args, **kwargs)
|
res = func(*args, **kwargs)
|
||||||
|
@ -12,10 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import io
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import yaql
|
import yaql
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import factory
|
from yaql.language import factory
|
||||||
@ -28,7 +27,7 @@ class TestEngine(tests.TestCase):
|
|||||||
def test_parser_grammar(self):
|
def test_parser_grammar(self):
|
||||||
# replace stderr with cString to write to
|
# replace stderr with cString to write to
|
||||||
copy = sys.stderr
|
copy = sys.stderr
|
||||||
sys.stderr = six.StringIO()
|
sys.stderr = io.StringIO()
|
||||||
try:
|
try:
|
||||||
debug_opts = dict(self.engine_options)
|
debug_opts = dict(self.engine_options)
|
||||||
debug_opts['yaql.debug'] = True
|
debug_opts['yaql.debug'] = True
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
@ -53,9 +51,9 @@ class TestTypeAggregation(yaql.tests.TestCase):
|
|||||||
|
|
||||||
def test_any_of(self):
|
def test_any_of(self):
|
||||||
@specs.parameter(
|
@specs.parameter(
|
||||||
'arg', yaqltypes.AnyOf(six.string_types, yaqltypes.Integer()))
|
'arg', yaqltypes.AnyOf(str, yaqltypes.Integer()))
|
||||||
def foo(arg):
|
def foo(arg):
|
||||||
if isinstance(arg, six.string_types):
|
if isinstance(arg, str):
|
||||||
return 1
|
return 1
|
||||||
if isinstance(arg, int):
|
if isinstance(arg, int):
|
||||||
return 2
|
return 2
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +54,7 @@ class YaqlInterface(object):
|
|||||||
context['$' + str(i + 1)] = arg_value
|
context['$' + str(i + 1)] = arg_value
|
||||||
|
|
||||||
kwargs = utils.convert_input_data(kwargs)
|
kwargs = utils.convert_input_data(kwargs)
|
||||||
for arg_name, arg_value in six.iteritems(kwargs):
|
for arg_name, arg_value in kwargs.items():
|
||||||
context['$' + arg_name] = arg_value
|
context['$' + arg_name] = arg_value
|
||||||
|
|
||||||
parsed = self.engine(__expression)
|
parsed = self.engine(__expression)
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
|
||||||
YAQLIZATION_ATTR = '__yaqlization__'
|
YAQLIZATION_ATTR = '__yaqlization__'
|
||||||
|
|
||||||
|
|
||||||
@ -56,8 +53,8 @@ def build_yaqlization_settings(
|
|||||||
blacklist = set(blacklist or [])
|
blacklist = set(blacklist or [])
|
||||||
attribute_remapping = attribute_remapping or {}
|
attribute_remapping = attribute_remapping or {}
|
||||||
if blacklist_remapped_attributes:
|
if blacklist_remapped_attributes:
|
||||||
for value in six.itervalues(attribute_remapping):
|
for value in attribute_remapping.values():
|
||||||
if not isinstance(value, six.string_types):
|
if not isinstance(value, str):
|
||||||
name = value[0]
|
name = value[0]
|
||||||
else:
|
else:
|
||||||
name = value
|
name = value
|
||||||
|
Loading…
Reference in New Issue
Block a user