Remove six

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I2f37e055838ea50627562d3585d6951f8d8d46aa
This commit is contained in:
Stephen Finucane 2021-02-01 10:31:03 +00:00
parent 8fcac72fd3
commit 4670f0949c
25 changed files with 4931 additions and 276 deletions

View File

@ -13,12 +13,12 @@
# under the License.
import importlib
import io
import operator
import pkgutil
import traceback
import types
import six
from docutils import nodes
from docutils.parsers import rst
from docutils import utils
@ -123,7 +123,7 @@ def write_module_doc(module, output):
method = getattr(module, name)
it = write_method_doc(method, output)
try:
name = six.next(it)
name = next(it)
seq.append((name, it))
except StopIteration:
pass
@ -169,7 +169,7 @@ def generate_doc(source):
package = importlib.import_module(source)
except ImportError:
return 'Error: No such module {0}'.format(source)
out = six.StringIO()
out = io.StringIO()
try:
if hasattr(package, '__path__'):
write_package_doc(package, out)

View File

@ -1,4 +1,3 @@
pbr>=1.8
python-dateutil>=2.4.2
ply
six>=1.9.0

View File

@ -13,16 +13,12 @@
# under the License.
import json
import locale
import os
import readline
import sys
import six
from yaql.language.exceptions import YaqlParsingException
from yaql import __version__ as version
from yaql.language.exceptions import YaqlParsingException
from yaql.language import utils
@ -46,10 +42,7 @@ def main(context, show_tokens, parser):
comm = True
while comm != 'exit':
try:
comm = six.moves.input(PROMPT)
if six.PY2:
comm = comm.decode(
sys.stdin.encoding or locale.getpreferredencoding(True))
comm = input(PROMPT)
except EOFError:
return
if not comm:

View File

@ -14,16 +14,13 @@
import abc
import six
from yaql.language import exceptions
from yaql.language import runner
from yaql.language import specs
from yaql.language import utils
@six.add_metaclass(abc.ABCMeta)
class ContextBase(object):
class ContextBase(metaclass=abc.ABCMeta):
def __init__(self, parent_context=None, convention=None):
self._parent_context = parent_context
self._convention = convention
@ -95,7 +92,7 @@ class ContextBase(object):
@abc.abstractmethod
def keys(self):
return six.iterkeys({})
return {}.keys()
class Context(ContextBase):
@ -115,8 +112,7 @@ class Context(ContextBase):
def register_function(self, spec, *args, **kwargs):
exclusive = kwargs.pop('exclusive', False)
if not isinstance(spec, specs.FunctionDefinition) \
and six.callable(spec):
if not isinstance(spec, specs.FunctionDefinition) and callable(spec):
spec = specs.get_function_definition(
spec, *args, convention=self._convention, **kwargs)
@ -139,7 +135,7 @@ class Context(ContextBase):
if predicate is None:
predicate = lambda x: True # noqa: E731
return (
set(six.moves.filter(predicate, self._functions.get(name, set()))),
set(filter(predicate, self._functions.get(name, set()))),
name in self._exclusive_funcs
)
@ -173,12 +169,12 @@ class Context(ContextBase):
def __contains__(self, item):
if isinstance(item, specs.FunctionDefinition):
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 False
def keys(self):
return six.iterkeys(self._data)
return self._data.keys()
class MultiContext(ContextBase):
@ -186,9 +182,9 @@ class MultiContext(ContextBase):
self._context_list = context_list
if convention is None:
convention = context_list[0].convention
parents = tuple(six.moves.filter(
lambda t: t,
six.moves.map(lambda t: t.parent, context_list)))
parents = tuple(
filter(lambda t: t, map(lambda t: t.parent, context_list))
)
if not parents:
super(MultiContext, self).__init__(None, convention)
elif len(parents) == 1:

View File

@ -15,11 +15,8 @@
import abc
import re
import six
@six.add_metaclass(abc.ABCMeta)
class Convention(object):
class Convention(metaclass=abc.ABCMeta):
@abc.abstractmethod
def convert_function_name(self, name):
pass

View File

@ -14,8 +14,6 @@
import sys
import six
import yaql
from yaql.language import exceptions
from yaql.language import utils
@ -26,7 +24,6 @@ class Expression(object):
pass
@six.python_2_unicode_compatible
class Function(Expression):
def __init__(self, name, *args):
self.name = name
@ -37,8 +34,7 @@ class Function(Expression):
return context(self.name, engine, receiver, context)(*self.args)
def __str__(self):
return u'{0}({1})'.format(self.name, ', '.join(
map(six.text_type, self.args)))
return '{0}({1})'.format(self.name, ', '.join(map(str, self.args)))
class BinaryOperator(Function):
@ -81,7 +77,6 @@ class MapExpression(Function):
self.uses_receiver = False
@six.python_2_unicode_compatible
class GetContextValue(Function):
def __init__(self, path):
super(GetContextValue, self).__init__('#get_context_data', path)
@ -92,16 +87,15 @@ class GetContextValue(Function):
return self.path.value
@six.python_2_unicode_compatible
class Constant(Expression):
def __init__(self, value):
self.value = value
self.uses_receiver = False
def __str__(self):
if isinstance(self.value, six.text_type):
return u"'{0}'".format(self.value)
return six.text_type(self.value)
if isinstance(self.value, str):
return "'{0}'".format(self.value)
return str(self.value)
def __call__(self, receiver, context, engine):
return self.value
@ -111,7 +105,6 @@ class KeywordConstant(Constant):
pass
@six.python_2_unicode_compatible
class Wrap(Expression):
def __init__(self, expression):
self.expr = expression
@ -124,7 +117,6 @@ class Wrap(Expression):
return self.expr(receiver, context, engine)
@six.python_2_unicode_compatible
class MappingRuleExpression(Expression):
def __init__(self, source, destination):
self.source = source
@ -140,7 +132,6 @@ class MappingRuleExpression(Expression):
self.destination(receiver, context, engine))
@six.python_2_unicode_compatible
class Statement(Function):
def __init__(self, expression, engine):
self.expression = expression
@ -155,7 +146,7 @@ class Statement(Function):
try:
return super(Statement, self).__call__(receiver, context, engine)
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):
if context is None or context is utils.NO_VALUE:

View File

@ -15,8 +15,6 @@
import codecs
import re
import six
from yaql.language import exceptions
@ -66,7 +64,7 @@ class Lexer(object):
'MAPPING',
'MAP'
] + 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 ('[]', '{}'):
continue
lexem_name = op_record[2]

4757
yaql/language/parser.out Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import types
from yaql.language import exceptions
from yaql.language import expressions
@ -71,9 +71,9 @@ class Parser(object):
p[0] = expressions.UnaryOperator(p[2], p[1], alias)
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
self.p_unary = six.create_bound_method(p_unary, self)
self.p_unary = types.MethodType(p_unary, self)
precedence = []
for i in range(1, len(precedence_dict) + 1):
@ -98,7 +98,7 @@ class Parser(object):
p[0] = expressions.Function('#call', p[1], *arg)
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
def p_value_to_const(p):

View File

@ -16,8 +16,6 @@
import sys
import six
from yaql.language import exceptions
from yaql.language import expressions
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))
return result
except StopIteration as e:
six.reraise(
exceptions.WrappedException,
exceptions.WrappedException(e),
raise exceptions.WrappedException(e).with_traceback(
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):
if isinstance(pos_arg.value_type, yaqltypes.LazyParameterType):
lazy.add(i)
for key, value in six.iteritems(kwd):
for key, value in kwd.items():
if isinstance(value.value_type, yaqltypes.LazyParameterType):
lazy.add(key)
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))
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
kwargs[key] = arg_evaluator(key, value)
delegate = None
@ -147,7 +143,7 @@ def choose_overload(name, candidates, engine, receiver, context, args, kwargs):
def translate_args(without_kwargs, args, kwargs):
if without_kwargs:
if len(kwargs) > 0:
raise exceptions.ArgumentException(six.next(iter(kwargs)))
raise exceptions.ArgumentException(next(iter(kwargs)))
return args, {}
pos_args = []
kw_args = {}
@ -161,7 +157,7 @@ def translate_args(without_kwargs, args, kwargs):
kw_args[param_name] = t.destination
else:
pos_args.append(t)
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
if key in kw_args:
raise exceptions.MappingTranslationException()
else:
@ -174,13 +170,13 @@ def _is_specialization_of(mapping1, mapping2):
args_mapping2, kwargs_mapping2 = mapping2
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):
return False
elif a1.value_type.is_specialization_of(a2.value_type):
res = True
for key, a1 in six.iteritems(kwargs_mapping1):
for key, a1 in kwargs_mapping1.items():
a2 = kwargs_mapping2[key]
if a2.value_type.is_specialization_of(a1.value_type):
return False

View File

@ -14,8 +14,6 @@
import inspect
import six
from yaql.language import exceptions
from yaql.language import utils
from yaql.language import yaqltypes
@ -66,9 +64,7 @@ class FunctionDefinition(object):
return func
def clone(self):
parameters = dict(
(key, p.clone())
for key, p in six.iteritems(self.parameters))
parameters = {key: p.clone() for key, p in self.parameters.items()}
res = FunctionDefinition(
self.name, self.payload, parameters, self.doc,
@ -79,12 +75,12 @@ class FunctionDefinition(object):
fd = self.clone()
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):
continue
keys_to_remove.add(k)
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:
v2.position -= 1
for key in keys_to_remove:
@ -101,67 +97,38 @@ class FunctionDefinition(object):
self.parameters[name.name] = 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)
spec = inspect.getfullargspec(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:
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]
raise IndexError('argument position is out of range')
arg_name = name
if name == spec.varkw:
position = None
arg_name = '**'
elif name == spec.varargs:
position = len(spec.args)
arg_name = '*'
elif name in spec.kwonlyargs:
position = None
elif name not in spec.args:
raise exceptions.NoParameterFoundException(
function_name=self.name or self.payload.__name__,
param_name=name)
else:
spec = inspect.getfullargspec(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')
position = spec.args.index(name)
arg_name = name
if name == spec.varkw:
position = None
arg_name = '**'
elif name == spec.varargs:
position = len(spec.args)
arg_name = '*'
elif name in spec.kwonlyargs:
position = None
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]
elif spec.kwonlydefaults is not None:
default = spec.kwonlydefaults.get(name, NO_DEFAULT)
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]
elif spec.kwonlydefaults is not None:
default = spec.kwonlydefaults.get(name, NO_DEFAULT)
if arg_name in self.parameters and not overwrite:
raise exceptions.DuplicateParameterDecoratorException(
@ -191,7 +158,7 @@ class FunctionDefinition(object):
def insert_parameter(self, name, value_type=None, nullable=None,
alias=None, overwrite=False):
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:
continue
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]
keyword_args = {}
for p in six.itervalues(self.parameters):
for p in self.parameters.values():
if p.position is not None and isinstance(
p.value_type, yaqltypes.HiddenParameterType):
for index in range(p.position + 1, len(positional_fix_table)):
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
if p.position is not None and key != '*':
arg_position = p.position - positional_fix_table[p.position]
@ -242,7 +209,7 @@ class FunctionDefinition(object):
if len(kwargs) > 0:
if '**' in self.parameters:
argdef = self.parameters['**']
for key in six.iterkeys(kwargs):
for key in kwargs:
keyword_args[key] = argdef
else:
return None
@ -255,7 +222,7 @@ class FunctionDefinition(object):
value = positional_args[i].default
if not positional_args[i].value_type.check(value, context, engine):
return None
for kwd in six.iterkeys(kwargs):
for kwd in kwargs:
if not keyword_args[kwd].value_type.check(
kwargs[kwd], context, engine):
return None
@ -278,7 +245,7 @@ class FunctionDefinition(object):
kwargs = kwargs.copy()
kwargs = dict(kwargs)
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 != '*':
positional += 1
@ -286,13 +253,13 @@ class FunctionDefinition(object):
positional_fix_table = positional * [0]
keyword_args = {}
for p in six.itervalues(self.parameters):
for p in self.parameters.values():
if p.position is not None and isinstance(
p.value_type, yaqltypes.HiddenParameterType):
for index in range(p.position + 1, positional):
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
if p.position is not None and key != '*':
if isinstance(p.value_type, yaqltypes.HiddenParameterType):
@ -332,7 +299,7 @@ class FunctionDefinition(object):
if len(kwargs) > 0:
if '**' in self.parameters:
argdef = self.parameters['**']
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
keyword_args[key] = checked(value, argdef)
else:
raise exceptions.ArgumentException('**')
@ -343,7 +310,7 @@ class FunctionDefinition(object):
*tuple(map(lambda t: t(new_context),
positional_args)),
**dict(map(lambda t: (t[0], t[1](new_context)),
six.iteritems(keyword_args)))
keyword_args.items()))
)
return result
@ -352,7 +319,7 @@ class FunctionDefinition(object):
def is_valid_method(self):
min_position = len(self.parameters)
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 \
not isinstance(p.value_type,
yaqltypes.HiddenParameterType):
@ -407,24 +374,14 @@ def get_function_definition(func, name=None, function=None, method=None,
if parameter_type_func is None:
parameter_type_func = _infer_parameter_type
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)
for arg in spec.args + spec.kwonlyargs:
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.varkw and '**' not in fd.parameters:
fd.set_parameter(spec.varkw, parameter_type_func(spec.varkw))
spec = inspect.getfullargspec(func)
for arg in spec.args + spec.kwonlyargs:
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.varkw and '**' not in fd.parameters:
fd.set_parameter(spec.varkw, parameter_type_func(spec.varkw))
if name is not None:
fd.name = name
@ -438,7 +395,7 @@ def get_function_definition(func, name=None, function=None, method=None,
if method is not None:
fd.is_method = method
if convention:
for p in six.itervalues(fd.parameters):
for p in fd.parameters.values():
if p.alias is None:
p.alias = convert_parameter_name(p.name, convention)
return fd

View File

@ -16,8 +16,6 @@ import collections
import re
import sys
import six
from yaql.language import exceptions
from yaql.language import lexer
@ -38,13 +36,15 @@ def is_iterator(obj):
def is_iterable(obj):
return isinstance(obj, collections.Iterable) and not isinstance(
obj, six.string_types + (MappingType,))
return (
isinstance(obj, collections.Iterable) and
not isinstance(obj, (str, MappingType))
)
def is_sequence(obj):
return isinstance(obj, collections.Sequence) and not isinstance(
obj, six.string_types)
obj, str)
def is_mutable(obj):
@ -67,17 +67,17 @@ QueueType = collections.deque
def convert_input_data(obj, rec=None):
if rec is None:
rec = convert_input_data
if isinstance(obj, six.string_types):
return obj if isinstance(obj, six.text_type) else six.text_type(obj)
if isinstance(obj, str):
return obj if isinstance(obj, str) else str(obj)
elif isinstance(obj, SequenceType):
return tuple(rec(t, rec) for t in obj)
elif isinstance(obj, MappingType):
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):
return frozenset(rec(t, rec) for t in obj)
elif isinstance(obj, IterableType):
return six.moves.map(lambda v: rec(v, rec), obj)
return map(lambda v: rec(v, rec), obj)
else:
return obj
@ -87,7 +87,7 @@ def convert_output_data(obj, limit_func, engine, rec=None):
rec = convert_output_data
if isinstance(obj, collections.Mapping):
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(
value, limit_func, engine, rec)
return result
@ -139,7 +139,7 @@ class FrozenDict(collections.Mapping):
def __hash__(self):
if self._hash is None:
self._hash = 0
for pair in six.iteritems(self):
for pair in self.items():
self._hash ^= hash(pair)
return self._hash
@ -153,7 +153,7 @@ def memorize(collection, engine):
yielded = []
class RememberingIterator(six.Iterator):
class RememberingIterator:
def __init__(self):
self.seq = iter(collection)
self.index = 0

View File

@ -17,7 +17,6 @@ import collections
import datetime
from dateutil import tz
import six
from yaql.language import exceptions
from yaql.language import expressions
@ -25,8 +24,7 @@ from yaql.language import utils
from yaql import yaql_interface
@six.add_metaclass(abc.ABCMeta)
class HiddenParameterType(object):
class HiddenParameterType(metaclass=abc.ABCMeta):
__slots__ = tuple()
# noinspection PyMethodMayBeStatic,PyUnusedLocal
@ -34,13 +32,11 @@ class HiddenParameterType(object):
return True
@six.add_metaclass(abc.ABCMeta)
class LazyParameterType(object):
class LazyParameterType(metaclass=abc.ABCMeta):
__slots__ = tuple()
@six.add_metaclass(abc.ABCMeta)
class SmartType(object):
class SmartType(metaclass=abc.ABCMeta):
__slots__ = ('nullable',)
def __init__(self, nullable):
@ -149,13 +145,13 @@ class String(PythonType):
__slots__ = tuple()
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,
*args, **kwargs):
value = super(String, self).convert(
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):
@ -163,7 +159,7 @@ class Integer(PythonType):
def __init__(self, nullable=False):
super(Integer, self).__init__(
six.integer_types, nullable=nullable,
int, nullable=nullable,
validators=[lambda t: not isinstance(t, bool)])
@ -189,9 +185,9 @@ class Iterable(PythonType):
def __init__(self, validators=None, nullable=False):
super(Iterable, self).__init__(
collections.Iterable, nullable, [
lambda t: not isinstance(t, six.string_types + (
utils.MappingType,))] + (validators or []))
collections.Iterable, nullable,
[lambda t: not isinstance(t, (str, utils.MappingType))] + (
validators or []))
def check(self, value, context, engine, *args, **kwargs):
if isinstance(value, utils.MappingType) and engine.options.get(
@ -222,7 +218,7 @@ class Sequence(PythonType):
def __init__(self, validators=None, nullable=False):
super(Sequence, self).__init__(
collections.Sequence, nullable, [
lambda t: not isinstance(t, six.string_types + (dict,))] + (
lambda t: not isinstance(t, (str, dict))] + (
validators or []))
@ -231,7 +227,7 @@ class Number(PythonType):
def __init__(self, nullable=False):
super(Number, self).__init__(
six.integer_types + (float,), nullable,
(int, float), nullable,
validators=[lambda t: not isinstance(t, bool)])
@ -260,7 +256,7 @@ class Lambda(LazyParameterType, SmartType):
self._publish_params(context, args, kwargs)
if isinstance(value, expressions.Expression):
result = value(receiver, context, engine)
elif six.callable(value):
elif callable(value):
result = value(*args, **kwargs)
else:
result = value
@ -273,7 +269,7 @@ class Lambda(LazyParameterType, SmartType):
*convert_args, **convert_kwargs)
if value is None:
return None
elif six.callable(value) and hasattr(value, '__unwrapped__'):
elif callable(value) and hasattr(value, '__unwrapped__'):
value = value.__unwrapped__
def func(*args, **kwargs):
@ -318,7 +314,7 @@ class Super(HiddenParameterType, SmartType):
def convert(self, value, receiver, context, function_spec, engine,
*convert_args, **convert_kwargs):
if six.callable(value) and hasattr(value, '__unwrapped__'):
if callable(value) and hasattr(value, '__unwrapped__'):
value = value.__unwrapped__
def func(*args, **kwargs):
@ -377,7 +373,7 @@ class Delegate(HiddenParameterType, SmartType):
def convert(self, value, receiver, context, function_spec, engine,
*convert_args, **convert_kwargs):
if six.callable(value) and hasattr(value, '__unwrapped__'):
if callable(value) and hasattr(value, '__unwrapped__'):
value = value.__unwrapped__
def func(*args, **kwargs):
@ -485,7 +481,7 @@ class StringConstant(Constant):
def check(self, value, context, *args, **kwargs):
return super(StringConstant, self).check(
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):
@ -519,13 +515,12 @@ class NumericConstant(Constant):
def check(self, value, context, *args, **kwargs):
return super(NumericConstant, self).check(
value, context, *args, **kwargs) and (
value is None or isinstance(
value.value, six.integer_types + (float,)) and
value is None or
isinstance(value.value, (int, float)) and
type(value.value) is not bool)
@six.add_metaclass(abc.ABCMeta)
class SmartTypeAggregation(SmartType):
class SmartTypeAggregation(SmartType, metaclass=abc.ABCMeta):
__slots__ = ('types',)
def __init__(self, *args, **kwargs):

View File

@ -17,8 +17,6 @@ Functions that produce or consume finite collections - lists, dicts and sets.
import itertools
import six
from yaql.language import specs
from yaql.language import utils
from yaql.language import yaqltypes
@ -328,7 +326,7 @@ def dict_set(engine, d, key, value):
{"a": 1, "b": 3}
"""
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')
@ -354,8 +352,7 @@ def dict_set_many(engine, d, replacements):
{"a": 1, "c": 4, "b": 3}
"""
utils.limit_memory_usage(engine, (1, d), (1, replacements))
return utils.FrozenDict(itertools.chain(
six.iteritems(d), six.iteritems(replacements)))
return utils.FrozenDict(itertools.chain(d.items(), replacements.items()))
@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))
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')
@ -403,7 +400,7 @@ def dict_keys(d):
yaql> {"a" => 1, "b" => 2}.keys()
["a", "b"]
"""
return six.iterkeys(d)
return d.keys()
@specs.parameter('d', utils.MappingType, alias='dict')
@ -424,7 +421,7 @@ def dict_values(d):
yaql> {"a" => 1, "b" => 2}.values()
[1, 2]
"""
return six.itervalues(d)
return d.values()
@specs.parameter('d', utils.MappingType, alias='dict')
@ -445,7 +442,7 @@ def dict_items(d):
yaql> {"a" => 1, "b" => 2}.items()
[["a", 1], ["b", 2]]
"""
return six.iteritems(d)
return d.items()
@specs.parameter('lst', yaqltypes.Sequence(), alias='list')
@ -563,7 +560,7 @@ def contains_value(d, value):
yaql> {"a" => 1, "b" => 2}.containsValue(2)
true
"""
return value in six.itervalues(d)
return value in d.values()
@specs.parameter('left', yaqltypes.Iterable())

View File

@ -19,8 +19,6 @@ Examples are provided with CLI started with legacy mode.
import itertools
import six
from yaql.language import contexts
from yaql.language import expressions
from yaql.language import specs
@ -124,7 +122,7 @@ def indexer(collection, index_expression):
index = index_expression()
if isinstance(index, int) and not isinstance(index, bool):
return collection[index]
return six.moves.filter(index_expression, collection)
return filter(index_expression, collection)
@specs.parameter('start', int)
@ -153,7 +151,7 @@ def range_(start, stop=None):
if stop is None:
return itertools.count(start)
else:
return six.moves.range(start, stop)
return range(start, stop)
@specs.parameter('conditions', yaqltypes.Lambda(with_context=True))

View File

@ -16,8 +16,6 @@ The Math module describes implemented math operations on numbers.
"""
import random
import six
from yaql.language import specs
from yaql.language import yaqltypes
@ -113,8 +111,7 @@ def division(left, right):
yaql> 3.0 / 2
1.5
"""
if isinstance(left, six.integer_types) and isinstance(
right, six.integer_types):
if isinstance(left, int) and isinstance(right, int):
return left // right
return left / right
@ -654,7 +651,7 @@ def is_integer(value):
yaql> isInteger(12)
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):
@ -674,8 +671,7 @@ def is_number(value):
yaql> isNumber(12)
true
"""
return (isinstance(value, six.integer_types + (float,))
and not isinstance(value, bool))
return isinstance(value, (int, float)) and not isinstance(value, bool)
def register(context):

View File

@ -19,10 +19,8 @@ Queries module.
# yaql.standard_library.collections
import collections
import functools
import itertools
import sys
import six
from yaql.language import exceptions
from yaql.language import specs
@ -110,7 +108,7 @@ def where(collection, predicate):
yaql> [1, 2, 3, 4, 5].where($ > 3)
[4, 5]
"""
return six.moves.filter(predicate, collection)
return filter(predicate, collection)
@specs.parameter('collection', yaqltypes.Iterable())
@ -136,7 +134,7 @@ def select(collection, selector):
yaql> [{'a'=> 2}, {'a'=> 4}].select($.a)
[2, 4]
"""
return six.moves.map(selector, collection)
return map(selector, collection)
@specs.parameter('collection', yaqltypes.Iterable())
@ -161,8 +159,7 @@ def collection_attribution(collection, attribute, operator):
yaql> [{"a" => 1}, {"a" => 2, "b" => 3}].a
[1, 2]
"""
return six.moves.map(
lambda t: operator(t, attribute), collection)
return map(lambda t: operator(t, attribute), collection)
@specs.parameter('collection', yaqltypes.Iterable())
@ -554,7 +551,7 @@ def first(collection, default=utils.NO_VALUE):
3
"""
try:
return six.next(iter(collection))
return next(iter(collection))
except StopIteration:
if default is utils.NO_VALUE:
raise
@ -582,9 +579,9 @@ def single(collection):
Execution exception: Collection contains more than one item
"""
it = iter(collection)
result = six.next(it)
result = next(it)
try:
six.next(it)
next(it)
except StopIteration:
return result
raise StopIteration('Collection contains more than one item')
@ -679,7 +676,7 @@ def range_(stop):
yaql> range(3)
[0, 1, 2]
"""
return iter(six.moves.range(stop))
return iter(range(stop))
@specs.parameter('start', int)
@ -708,7 +705,7 @@ def range__(start, stop, step=1):
yaql> range(4, 1, -1)
[4, 3, 2]
"""
return iter(six.moves.range(start, stop, step))
return iter(range(start, stop, step))
@specs.parameter('start', int)
@ -877,16 +874,20 @@ class GroupAggregator(object):
key, value_list = group_item
try:
result = self.aggregator(value_list)
except (exceptions.NoMatchingMethodException,
exceptions.NoMatchingFunctionException,
IndexError):
self._failure_info = sys.exc_info()
except (
exceptions.NoMatchingMethodException,
exceptions.NoMatchingFunctionException,
IndexError,
) as exc:
self._failure_info = exc
else:
if not (len(value_list) == 2 and
isinstance(result, collections.Sequence) and
not isinstance(result, six.string_types) and
len(result) == 2 and
result[0] == value_list[0]):
if not (
len(value_list) == 2 and
isinstance(result, collections.Sequence) and
not isinstance(result, str) and
len(result) == 2 and
result[0] == value_list[0]
):
# We are not dealing with (correct) version 1.1.1 syntax,
# so don't bother trying to fall back if there's an error
# with a later group.
@ -905,7 +906,7 @@ class GroupAggregator(object):
# If we are unable to successfully fall back, re-raise the first
# 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):
@ -952,7 +953,7 @@ def group_by_function(allow_aggregator_fallback):
value = t if value_selector is None else value_selector(t)
groups.setdefault(key_selector(t), []).append(value)
utils.limit_memory_usage(engine, (1, groups))
return select(six.iteritems(groups), new_aggregator)
return select(groups.items(), new_aggregator)
return group_by
@ -978,7 +979,7 @@ def zip_(*collections):
yaql> [1, 2, 3].zip([4, 5], [6, 7])
[[1, 4, 6], [2, 5, 7]]
"""
return six.moves.zip(*collections)
return zip(*collections)
@specs.method
@ -1008,7 +1009,7 @@ def zip_longest(*collections, **kwargs):
yaql> [1, 2, 3].zipLongest([4, 5], default => 100)
[[1, 4], [2, 5], [3, 100]]
"""
return six.moves.zip_longest(
return itertools.zip_longest(
*collections, fillvalue=kwargs.pop('default', None))
@ -1424,9 +1425,9 @@ def aggregate(collection, selector, seed=utils.NO_VALUE):
1
"""
if seed is utils.NO_VALUE:
return six.moves.reduce(selector, collection)
return functools.reduce(selector, collection)
else:
return six.moves.reduce(selector, collection, seed)
return functools.reduce(selector, collection, seed)
@specs.method
@ -1452,7 +1453,7 @@ def reverse(collection, to_list):
def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
result = {}
for key, value1 in six.iteritems(dict1):
for key, value1 in dict1.items():
result[key] = value1
if key in dict2:
value2 = dict2[key]
@ -1473,7 +1474,7 @@ def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
else:
result[key] = item_merger(value1, value2)
for key2, value2 in six.iteritems(dict2):
for key2, value2 in dict2.items():
if key2 not in result:
result[key2] = value2
return result

View File

@ -17,8 +17,6 @@ The module contains functions for regular expressions.
import re
import six
from yaql.language import specs
from yaql.language import yaqltypes
@ -226,7 +224,7 @@ def _publish_match(context, match):
}
context['$' + str(i + 1)] = rec
for key, value, in six.itervalues(match.groupdict()):
for key, value, in match.groupdict().values():
rec = {
'value': value,
'start': match.start(value),

View File

@ -17,8 +17,6 @@ The module describes which operations can be done with strings in YAQL.
import string as string_module
import six
from yaql.language import specs
from yaql.language import utils
from yaql.language import yaqltypes
@ -299,7 +297,7 @@ def join(sequence, separator, str_delegate):
yaql> ["abc", "de", "f"].join("|")
"abc|de|f"
"""
return separator.join(six.moves.map(str_delegate, sequence))
return separator.join(map(str_delegate, sequence))
@specs.parameter('sequence', yaqltypes.Iterable())
@ -351,7 +349,7 @@ def str_(value):
elif value is False:
return 'false'
else:
return six.text_type(value)
return str(value)
@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)
"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)
return string
@ -955,7 +953,7 @@ def is_string(arg):
yaql> isString(1)
false
"""
return isinstance(arg, six.string_types)
return isinstance(arg, str)
@specs.parameter('string', yaqltypes.String())

View File

@ -17,8 +17,6 @@ The module describes main system functions for working with objects.
import itertools
import six
from yaql.language import contexts
from yaql.language import specs
from yaql.language import utils
@ -175,7 +173,7 @@ def let(__context__, *args, **kwargs):
for i, value in enumerate(args, 1):
__context__[str(i)] = value
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
__context__[key] = value
return __context__
@ -267,7 +265,7 @@ def assert__(engine, obj, condition, message=u'Assertion failed'):
@specs.name('#call')
@specs.parameter('callable_', yaqltypes.PythonType(
object, False, validators=(six.callable,)))
object, False, validators=(callable,)))
def call(callable_, *args, **kwargs):
""":yaql:call

View File

@ -47,8 +47,6 @@ This module provides implemented operators on Yaqlized objects.
import re
import six
from yaql.language import expressions
from yaql.language import runner
from yaql.language import specs
@ -83,7 +81,7 @@ def _match_name_to_entry(name, entry):
return True
elif isinstance(entry, REGEX_TYPE):
return entry.search(name) is not None
elif six.callable(entry):
elif callable(entry):
return entry(name)
return False
@ -143,7 +141,7 @@ def op_dot(receiver, expr, context, engine):
mappings = _remap_name(expr.name, settings)
_validate_name(expr.name, settings)
if not isinstance(mappings, six.string_types):
if not isinstance(mappings, str):
name = mappings[0]
if len(mappings) > 0:
arg_mappings = mappings[1]
@ -156,7 +154,7 @@ def op_dot(receiver, expr, context, engine):
func = getattr(receiver, name)
args, kwargs = runner.translate_args(False, expr.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(
utils.NO_VALUE, context, engine)
res = func(*args, **kwargs)

View File

@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import sys
import six
import yaql
from yaql.language import exceptions
from yaql.language import factory
@ -28,7 +27,7 @@ class TestEngine(tests.TestCase):
def test_parser_grammar(self):
# replace stderr with cString to write to
copy = sys.stderr
sys.stderr = six.StringIO()
sys.stderr = io.StringIO()
try:
debug_opts = dict(self.engine_options)
debug_opts['yaql.debug'] = True

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from yaql.language import exceptions
from yaql.language import specs
from yaql.language import yaqltypes
@ -53,9 +51,9 @@ class TestTypeAggregation(yaql.tests.TestCase):
def test_any_of(self):
@specs.parameter(
'arg', yaqltypes.AnyOf(six.string_types, yaqltypes.Integer()))
'arg', yaqltypes.AnyOf(str, yaqltypes.Integer()))
def foo(arg):
if isinstance(arg, six.string_types):
if isinstance(arg, str):
return 1
if isinstance(arg, int):
return 2

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from yaql.language import utils
@ -56,7 +54,7 @@ class YaqlInterface(object):
context['$' + str(i + 1)] = arg_value
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
parsed = self.engine(__expression)

View File

@ -12,9 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
YAQLIZATION_ATTR = '__yaqlization__'
@ -56,8 +53,8 @@ def build_yaqlization_settings(
blacklist = set(blacklist or [])
attribute_remapping = attribute_remapping or {}
if blacklist_remapped_attributes:
for value in six.itervalues(attribute_remapping):
if not isinstance(value, six.string_types):
for value in attribute_remapping.values():
if not isinstance(value, str):
name = value[0]
else:
name = value