Update to version 1.0.9

This commit is contained in:
Davide Brunato 2018-06-15 18:14:43 +02:00
parent 777ce76e64
commit f4c4894278
11 changed files with 39 additions and 35 deletions

View File

@ -1,6 +1,6 @@
===========
***********
elementpath
===========
***********
.. elementpath-introduction
@ -16,7 +16,7 @@ language provides. If you want you can contribute to add an unimplemented functi
Installation and usage
----------------------
======================
You can install the package with *pip* in a Python 2.7 or Python 3.3+ environment::
@ -68,7 +68,7 @@ Public API classes and functions are described into the
`elementpath manual on the "Read the Docs" site <http://elementpath.readthedocs.io/en/latest/>`_.
Contributing
------------
============
You can contribute to this package reporting bugs, using the issue tracker or by a pull request.
In case you open an issue please try to provide a test or test data for reproducing the wrong
@ -85,7 +85,7 @@ implement other types of parsers (I think it could be also a funny exercise!).
License
-------
=======
This software is distributed under the terms of the MIT License.
See the file 'LICENSE' in the root directory of the present

View File

@ -31,7 +31,7 @@ author = 'Davide Brunato'
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '1.0.8'
release = '1.0.9'
# -- General configuration ---------------------------------------------------

View File

@ -1,5 +1,6 @@
************
Introduction
============
************
.. include:: ../README.rst
:start-after: elementpath-introduction
:start-after: elementpath-introduction

View File

@ -1,5 +1,6 @@
******************
Pratt's parser API
==================
******************
The TDOP (Top Down Operator Precedence) parser implemented within this library is a variant of the
original Pratt's parser based on a class for the parser and metaclasses for tokens.
@ -10,7 +11,7 @@ methods and attributes to help the developing of new parsers. Parsers can be def
by class derivation and following a tokens registration procedure.
Token base class
----------------
================
.. autoclass:: elementpath.Token
@ -34,7 +35,7 @@ Token base class
Parser base class
-----------------
=================
.. autoclass:: elementpath.Parser
@ -48,8 +49,6 @@ Parser base class
Helper methods for building effective parser classes:
.. automethod:: begin
.. automethod:: end
.. automethod:: register
.. automethod:: unregister
.. automethod:: unregistered
@ -60,3 +59,4 @@ Parser base class
.. automethod:: infix
.. automethod:: infixr
.. automethod:: method
.. automethod:: end

View File

@ -1,10 +1,11 @@
****************
Public XPath API
================
****************
The package includes some classes and functions that implement XPath parsers and selectors.
XPath tokens
------------
============
.. autoclass:: elementpath.XPathToken
@ -13,7 +14,7 @@ XPath tokens
XPath parsers
-------------
=============
.. autoclass:: elementpath.XPath1Parser
@ -23,7 +24,7 @@ XPath parsers
XPath selectors
---------------
===============
.. autofunction:: elementpath.select
@ -37,7 +38,7 @@ XPath selectors
XPath dynamic context
---------------------
=====================
.. autoclass:: elementpath.XPathContext

View File

@ -8,7 +8,7 @@
#
# @author Davide Brunato <brunato@sissa.it>
#
__version__ = '1.0.8'
__version__ = '1.0.9'
__author__ = "Davide Brunato"
__contact__ = "brunato@sissa.it"
__copyright__ = "Copyright 2018, SISSA"

View File

@ -22,6 +22,9 @@ from .exceptions import (
ElementPathSyntaxError, ElementPathNameError, ElementPathValueError, ElementPathTypeError
)
DEFAULT_SPECIAL_SYMBOLS = {'(string)', '(float)', '(decimal)', '(integer)', '(name)', '(end)'}
"""Special symbols for literals, names and end tokens."""
SPECIAL_SYMBOL_REGEX = re.compile(r'\s*\(\w+\)\s*')
"""Compiled regular expression for matching special symbols, that are names between round brackets."""
@ -274,6 +277,8 @@ class Parser(object):
(\S) | # Unexpected characters
\s+ # Skip extra spaces
"""
if not all(k in cls.symbol_table for k in DEFAULT_SPECIAL_SYMBOLS):
raise ValueError("The symbol table of %r doesn't contain all special symbols." % cls)
patterns = [
s.pattern for s in cls.symbol_table.values()
@ -296,7 +301,7 @@ class Parser(object):
cls.tokenizer = re.compile(pattern, re.VERBOSE)
def __init__(self):
if '(end)' not in self.symbol_table or self.tokenizer is None:
if self.tokenizer is None:
raise ValueError("Incomplete parser class %s registration." % self.__class__.__name__)
self.token = None
self.match = None
@ -492,7 +497,7 @@ class Parser(object):
@classmethod
def end(cls):
"""End the symbols registration and build the tokenizer."""
"""Registers the end symbol and builds the tokenizer."""
cls.register('(end)')
cls.build_tokenizer()

View File

@ -9,7 +9,6 @@
# @author Davide Brunato <brunato@sissa.it>
#
from __future__ import division
import sys
import math
import decimal
@ -94,17 +93,14 @@ class XPath1Parser(Parser):
self.variables = dict(variables if variables is not None else [])
self.strict = strict
@classmethod
def build_tokenizer(cls, name_pattern=XML_NCNAME_PATTERN):
super(XPath1Parser, cls).build_tokenizer(name_pattern)
@property
def version(self):
return '1.0'
@classmethod
def end(cls):
cls.register('(end)')
cls.build_tokenizer(name_pattern=XML_NCNAME_PATTERN)
for token_class in cls.symbol_table.values():
setattr(sys.modules[cls.__module__], token_class.__name__, token_class)
@classmethod
def axis(cls, symbol, bp=0):
"""Register a token for a symbol that represents an XPath *axis*."""
@ -1129,4 +1125,5 @@ def evaluate(self, context=None):
self.wrong_value(str(err))
XPath1Parser.end()
register('(end)')
XPath1Parser.build_tokenizer()

View File

@ -117,7 +117,7 @@ class XPath2Parser(XPath1Parser):
symbol = qname_to_prefixed(xsd_type.name, self.namespaces)
if symbol not in self.symbol_table:
self.atomic_type(symbol, xsd_type.name)
self.end()
self.build_tokenizer()
if compatibility_mode is False:
self.compatibility_mode = False
@ -1102,4 +1102,4 @@ def evaluate(self, context=None):
return context.item[1]
XPath2Parser.end()
XPath2Parser.build_tokenizer()

View File

@ -15,7 +15,7 @@ with open("README.rst") as readme:
setup(
name='elementpath',
version='1.0.8',
version='1.0.9',
packages=['elementpath'],
author='Davide Brunato',
author_email='brunato@sissa.it',

View File

@ -27,7 +27,7 @@ from elementpath.namespaces import (
try:
# noinspection PyPackageRequirements
import xmlschema
except ImportError:
except (ImportError, AttributeError):
xmlschema = None
@ -1173,7 +1173,7 @@ class LxmlXPath2ParserTest(XPath2ParserTest):
cls.etree = lxml.etree
@unittest.skipIf(xmlschema is None, "The xmlschema library is not installed.")
@unittest.skipIf(xmlschema is None, "xmlschema library >= v0.9.31 required.")
class XPath2ParserXMLSchemaTest(XPath2ParserTest):
if xmlschema: