From f6f81e3ed9fdf368ac9d4c2727bcd52ccd5e3684 Mon Sep 17 00:00:00 2001 From: Serg Melikyan Date: Mon, 26 Aug 2013 13:26:46 +0400 Subject: [PATCH 1/3] Bumped version to 0.2 Removed previously commited workaround. Note: Version should be changed in setup.py and yaql/__init__.py --- setup.py | 2 +- yaql/__init__.py | 4 +++- yaql/cli/cli_functions.py | 8 +++++++- yaql/functions/builtin.py | 18 ++++++++++-------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index ff07480..812545b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ from setuptools import setup, find_packages setup(name='yaql', - version='0.1', + version='0.2', description="Yet Another Query Language", author='Mirantis, Inc.', author_email='info@mirantis.com', diff --git a/yaql/__init__.py b/yaql/__init__.py index ed17916..4c8613f 100644 --- a/yaql/__init__.py +++ b/yaql/__init__.py @@ -16,6 +16,9 @@ import parser import context from yaql.functions import builtin, extended +__versioninfo__ = (0, 2, 0) +__version__ = '.'.join(map(str, __versioninfo__)) + def parse(expression): return parser.parse(expression) @@ -27,4 +30,3 @@ def create_context(include_extended_functions=True): if include_extended_functions: extended.add_to_context(cont) return context.Context(cont) - diff --git a/yaql/cli/cli_functions.py b/yaql/cli/cli_functions.py index d5730e2..f3d37cb 100644 --- a/yaql/cli/cli_functions.py +++ b/yaql/cli/cli_functions.py @@ -19,22 +19,28 @@ import yaql import readline from json import JSONDecoder +from yaql import __version__ as version from yaql.context import ContextAware, Context -from yaql.exceptions import YaqlParsingException, YaqlException +from yaql.exceptions import YaqlParsingException from yaql.utils import limit + PROMPT = "yaql> " @ContextAware() def main(context): print "Yet Another Query Language - command-line query tool" + print "Version {0}".format(version) print "Copyright (c) 2013 Mirantis, Inc" print if not context.get_data(): print "No data loaded into context " print "Type '@load data-file.json' to load data" print + + readline.parse_and_bind('') + comm = True while comm != 'exit': try: diff --git a/yaql/functions/builtin.py b/yaql/functions/builtin.py index 6a51ce8..3c68d0b 100644 --- a/yaql/functions/builtin.py +++ b/yaql/functions/builtin.py @@ -128,19 +128,21 @@ def divide(a, b): # Boolean operations -# @EvalArg('a', arg_type=types.BooleanType) -# @EvalArg('b', arg_type=types.BooleanType) +@EvalArg('a', arg_type=types.BooleanType) +@EvalArg('b', arg_type=types.BooleanType) def _and(a, b): - return a() and b() + return a and b -# @EvalArg('a', arg_type=types.BooleanType) -# @EvalArg('b', arg_type=types.BooleanType) + +@EvalArg('a', arg_type=types.BooleanType) +@EvalArg('b', arg_type=types.BooleanType) def _or(a, b): - return a() or b() + return a or b -# @EvalArg('self', arg_type=types.BooleanType) + +@EvalArg('self', arg_type=types.BooleanType) def _not(self): - return not self() + return not self #data structure creations From bdfcb1d13c2573bc64301b08f1818c790c222447 Mon Sep 17 00:00:00 2001 From: ativelkov Date: Mon, 13 Jan 2014 13:41:19 -0800 Subject: [PATCH 2/3] Modified some builtin functions (attribution, filtering) etc to handle objects and dictionary properly: Strings are not treated as collections anymore. Exception is now thrown if an unknown property is attempted to be retrieved for an object. Filtering with non-boolean predicates is no longer possible --- yaql/functions/builtin.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/yaql/functions/builtin.py b/yaql/functions/builtin.py index 3c68d0b..c958e49 100644 --- a/yaql/functions/builtin.py +++ b/yaql/functions/builtin.py @@ -16,15 +16,14 @@ import collections import types from yaql.context import EvalArg from yaql.context import ContextAware +from yaql.exceptions import YaqlExecutionException from yaql.utils import limit def _get_att_or_key(item, value): - if hasattr(item, value): - return getattr(item, value) if isinstance(item, types.DictionaryType): return item.get(value) - return None + return getattr(item, value) # basic language operations: @@ -36,7 +35,8 @@ def get_context_data(context, path): @EvalArg('self', arg_type=collections.Iterable, - custom_validator=lambda v: not isinstance(v, types.DictionaryType)) + custom_validator=lambda v: not isinstance(v, types.DictionaryType) + and not isinstance(v, types.StringTypes)) def collection_attribution(self, att_name): for item in self: val = _get_att_or_key(item, att_name()) @@ -54,7 +54,7 @@ def dict_attribution(self, arg_name): def obj_attribution(self, arg_name): - return getattr(self(), arg_name(), None) + return getattr(self(), arg_name()) def wrap(value): @@ -71,10 +71,14 @@ def get_by_index(this, index): return this[index] +@EvalArg("self", arg_type=collections.Iterable, + custom_validator=lambda v: not isinstance(v, types.StringTypes)) def filter_by_predicate(self, predicate): - for item in self(): + for item in self: r = predicate(item) - if r: + if not isinstance(r, types.BooleanType): + raise YaqlExecutionException() + if r is True: yield item From ae6636a97ad66b95b0692408e262bdd2a72d24d4 Mon Sep 17 00:00:00 2001 From: ativelkov Date: Mon, 13 Jan 2014 13:42:25 -0800 Subject: [PATCH 3/3] CLI is now called as "yaql" command, not "yaql-cli" Incremented version to 0.2.1 --- setup.py | 4 ++-- yaql/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 812545b..4bd677f 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ from setuptools import setup, find_packages setup(name='yaql', - version='0.2', + version='0.2.1', description="Yet Another Query Language", author='Mirantis, Inc.', author_email='info@mirantis.com', @@ -23,7 +23,7 @@ setup(name='yaql', install_requires=['ply'], entry_points={ 'console_scripts': [ - 'yaql-cli = yaql.cli.run:main', + 'yaql=yaql.cli.run:main', ] }, packages=find_packages(), diff --git a/yaql/__init__.py b/yaql/__init__.py index 4c8613f..ff5c86d 100644 --- a/yaql/__init__.py +++ b/yaql/__init__.py @@ -16,7 +16,7 @@ import parser import context from yaql.functions import builtin, extended -__versioninfo__ = (0, 2, 0) +__versioninfo__ = (0, 2, 1) __version__ = '.'.join(map(str, __versioninfo__))