Skip to content

Commit

Permalink
Flake8 the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Apr 5, 2019
1 parent 8f7b7e0 commit 59bd415
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 119 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ matrix:
dist: xenial
- python: "3.8-dev"
dist: xenial
- name: "flake8"
install: pip install flake8
script: flake8 src setup.py
after_success:
install:
- pip install -U pip setuptools
- pip install -U coverage coverage-python-version coveralls
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- Fix test failures and deprecation warnings occurring when using Python 3.8a1.
(`#15 <https://github.com/zopefoundation/zope.tales/pull/15>`_)

- Flake8 the code.


4.3 (2018-10-05)
================
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[bdist_wheel]
universal = 1

[flake8]
doctests = yes
115 changes: 59 additions & 56 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,65 +26,68 @@ def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()


TESTS_REQUIRE = [
'zope.testing',
'zope.testrunner',
]

setup(name='zope.tales',
version='5.0.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Template Application Language Expression Syntax '
'(TALES)',
long_description=(
read('README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
keywords="zope template xml tales",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3',
],
url='https://github.com/zopefoundation/zope.tales',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
extras_require={
'test': TESTS_REQUIRE,
'tal': [
'zope.tal',
],
'docs': [
'Sphinx',
'repoze.sphinx.autointerface',
'zope.tal',
],
},
install_requires=[
'setuptools',
'zope.interface',
'six',
],
tests_require=TESTS_REQUIRE,
include_package_data=True,
zip_safe=False,

setup(
name='zope.tales',
version='5.0.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Template Application Language Expression Syntax '
'(TALES)',
long_description=(
read('README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
keywords="zope template xml tales",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3',
],
url='https://github.com/zopefoundation/zope.tales',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
extras_require={
'test': TESTS_REQUIRE,
'tal': [
'zope.tal',
],
'docs': [
'Sphinx',
'repoze.sphinx.autointerface',
'zope.tal',
],
},
install_requires=[
'setuptools',
'zope.interface',
'six',
],
tests_require=TESTS_REQUIRE,
include_package_data=True,
zip_safe=False,
)
1 change: 0 additions & 1 deletion src/zope/tales/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
##############################################################################
"""Template Attribute Language - Expression Syntax
"""

7 changes: 5 additions & 2 deletions src/zope/tales/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from zope.tales.expressions import SimpleModuleImporter
from zope.tales.pythonexpr import PythonExpr


def DefaultEngine():
"""
Create and return an instance of :class:`~.ExpressionEngine` (an
Expand All @@ -44,8 +45,9 @@ def DefaultEngine():
``modules``
:class:`.SimpleModuleImporter`
In addition, the default ``path`` expressions (``standard``, ``path``, ``exists``
and ``nocall``), all implemented by :class:`.PathExpr`, are registered.
In addition, the default ``path`` expressions (``standard``, ``path``,
``exists`` and ``nocall``), all implemented by :class:`.PathExpr`, are
registered.
"""
e = ExpressionEngine()
reg = e.registerType
Expand All @@ -59,4 +61,5 @@ def DefaultEngine():
e.registerBaseName('modules', SimpleModuleImporter())
return e


Engine = DefaultEngine()
15 changes: 9 additions & 6 deletions src/zope/tales/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
Expression objects are created by the :class:`.ExpressionEngine`
(they must have previously been registered with
:func:`~zope.tales.tales.ExpressionEngine.registerType`). The expression object itself
is a callable object taking one argument, *econtext*, which is the local
expression namespace.
:func:`~zope.tales.tales.ExpressionEngine.registerType`). The expression
object itself is a callable object taking one argument, *econtext*, which is
the local expression namespace.
"""
import re
Expand All @@ -38,6 +38,7 @@

PY2 = sys.version_info[0] == 2


def simpleTraverse(object, path_items, econtext):
"""Traverses a sequence of names, first trying attributes then items.
"""
Expand Down Expand Up @@ -168,7 +169,7 @@ class PathExpr(object):
'path',
'exists',
'nocall',
)
)

def __init__(self, name, expr, engine, traverser=simpleTraverse):
self._s = expr
Expand Down Expand Up @@ -240,11 +241,11 @@ def __repr__(self):
return '<PathExpr %s:%s>' % (self._name, repr(self._s))



_interp = re.compile(
r'\$(%(n)s)|\${(%(n)s(?:/[^}|]*)*(?:\|%(n)s(?:/[^}|]*)*)*)}'
% {'n': NAME_RE})


@implementer(ITALESExpression)
class StringExpr(object):
"""
Expand All @@ -264,7 +265,8 @@ def __init__(self, name, expr, engine):
path_type = engine.getTypes()['path']
parts = []
for exp in expr.split('$$'):
if parts: parts.append('$')
if parts:
parts.append('$')
m = _interp.search(exp)
while m is not None:
parts.append(exp[:m.start()])
Expand Down Expand Up @@ -365,6 +367,7 @@ def __call__(self):
self._result = r = self._expr(self._econtext)
return r


class LazyExpr(DeferExpr):
"""
An expression that will defer evaluation of its
Expand Down
2 changes: 2 additions & 0 deletions src/zope/tales/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ITALESFunctionNamespace(Interface):
def setEngine(engine):
"""Sets the engine that is used to evaluate TALES expressions."""


class ITALESExpression(Interface):
"""TALES expression
Expand All @@ -46,6 +47,7 @@ def __call__(econtext):
*econtext* and return computed value.
"""


class ITALESIterator(ITALIterator):
"""TAL Iterator provided by TALES.
Expand Down
5 changes: 3 additions & 2 deletions src/zope/tales/pythonexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Generic Python Expression Handler
"""


class PythonExpr(object):
"""
Evaluates a python expression by calling :func:`eval` after
Expand All @@ -25,8 +26,8 @@ def __init__(self, name, expr, engine):
:param ExpressionEngine engine: The expression compiler that
is creating us.
"""
text = '\n'.join(expr.splitlines()) # normalize line endings
text = '(' + text + ')' # Put text in parens so newlines don't matter
text = '\n'.join(expr.splitlines()) # normalize line endings
text = '(' + text + ')' # Put text in parens so newlines don't matter
self.text = text
try:
code = self._compile(text, '<string>')
Expand Down
Loading

0 comments on commit 59bd415

Please sign in to comment.