Skip to content

Commit

Permalink
:add: dependency to six and try to execute unittests with python2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
b3j0f committed Nov 8, 2015
1 parent 200c125 commit 5101059
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 34 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
language: python
python:
- "2.5"
- "2.6"
- "2.7"
#- "3.2"
Expand Down
57 changes: 26 additions & 31 deletions b3j0f/aop/advice.py
Expand Up @@ -25,8 +25,7 @@
# --------------------------------------------------------------------

"""Provides functions in order to weave/unweave/get advices from callable
objects.
"""
objects."""

from re import compile as re_compile

Expand All @@ -46,7 +45,7 @@
super_method, get_intercepted, base_ctx
)

from b3j0f.utils.version import basestring
from six import string_types, callable

__all__ = [
'AdviceError', 'get_advices', 'weave', 'unweave', 'weave_on', 'Advice'
Expand All @@ -62,10 +61,7 @@


class AdviceError(Exception):
"""Handle Advice errors
"""

pass
"""Handle Advice errors."""


class _Joinpoint(Joinpoint):
Expand Down Expand Up @@ -214,8 +210,7 @@ def get_advices(target, ctx=None, local=False):


def _namematcher(regex):
"""Checks if a target name matches with an input regular expression
"""
"""Checks if a target name matches with an input regular expression."""

matcher = re_compile(regex)

Expand All @@ -232,8 +227,10 @@ def _publiccallable(target):
:return: True iif target is callable and name does not start with '_'
"""

result = callable(target) \
result = (
callable(target)
and not getattr(target, '__name__', '').startswith('_')
)

return result

Expand Down Expand Up @@ -282,7 +279,7 @@ def weave(
if pointcut is None or callable(pointcut):
pass
# in case of str, use a name matcher
elif isinstance(pointcut, basestring):
elif isinstance(pointcut, string_types):
pointcut = _namematcher(pointcut)
else:
error_msg = "Wrong pointcut to check weaving on {0}."
Expand Down Expand Up @@ -321,8 +318,8 @@ def weave(


def _weave(
target, advices, pointcut, ctx, depth, depth_predicate, intercepted,
pointcut_application
target, advices, pointcut, ctx, depth, depth_predicate, intercepted,
pointcut_application
):
"""Weave deeply advices in target.
Expand Down Expand Up @@ -388,7 +385,7 @@ def _weave(
# get the right ctx
if ctx is None:
ctx = target
for name, member in getmembers(ctx, depth_predicate):
for _, member in getmembers(ctx, depth_predicate):
_weave(
target=member, advices=advices, pointcut=pointcut,
depth_predicate=depth_predicate, intercepted=intercepted,
Expand Down Expand Up @@ -433,7 +430,7 @@ def unweave(
pass

# in case of str, use a name matcher
elif isinstance(pointcut, basestring):
elif isinstance(pointcut, string_types):
pointcut = _namematcher(pointcut)

else:
Expand All @@ -457,8 +454,7 @@ def unweave(


def _unweave(target, advices, pointcut, ctx, depth, depth_predicate):
"""Unweave deeply advices in target.
"""
"""Unweave deeply advices in target."""

# if weaving has to be done
if pointcut is None or pointcut(target):
Expand All @@ -472,7 +468,7 @@ def _unweave(target, advices, pointcut, ctx, depth, depth_predicate):
_base_ctx = None
if ctx is not None:
_base_ctx = base_ctx(ctx)
for name, member in getmembers(target, depth_predicate):
for _, member in getmembers(target, depth_predicate):
_unweave(
target=member, advices=advices, pointcut=pointcut,
depth=depth - 1, depth_predicate=depth_predicate, ctx=_base_ctx
Expand All @@ -499,6 +495,7 @@ def weave_on(advices, pointcut=None, ctx=None, depth=1, ttl=None):
"""

def __weave(target):
"""Internal weave function."""
weave(
target=target, advices=advices, pointcut=pointcut,
ctx=ctx, depth=depth, ttl=ttl
Expand All @@ -524,6 +521,8 @@ def __init__(self, impl, uid=None, enable=True):

@property
def uid(self):
"""Get advice uid."""

return self._uid

@property
Expand All @@ -537,8 +536,7 @@ def enable(self):

@enable.setter
def enable(self, value):
"""Change of enable status.
"""
"""Change of enable status."""

self._enable = value

Expand All @@ -550,6 +548,7 @@ def apply(self, joinpoint):

if self._enable:
result = self._impl(joinpoint)

else:
result = joinpoint.proceed()

Expand All @@ -574,8 +573,7 @@ def set_enable(target, enable=True, advice_ids=None):

@staticmethod
def weave(target, advices, pointcut=None, depth=1, public=False):
"""Weave advices such as Advice objects.
"""
"""Weave advices such as Advice objects."""

advices = (
advice if isinstance(advice, Advice) else Advice(advice)
Expand All @@ -589,8 +587,7 @@ def weave(target, advices, pointcut=None, depth=1, public=False):

@staticmethod
def unweave(target, *advices):
"""Unweave advices from input target.
"""
"""Unweave advices from input target."""

advices = (
advice if isinstance(advice, Advice) else Advice(advice)
Expand All @@ -600,22 +597,20 @@ def unweave(target, *advices):
unweave(target=target, *advices)

def __call__(self, joinpoint):
"""Shortcut for self apply.
"""
"""Shortcut for self apply."""

return self.apply(joinpoint)

def __hash__(self):
"""Return self uid hash.
"""
"""Return self uid hash."""

result = hash(self._uid)

return result

def __eq__(self, other):
"""Compare with self uid.
"""
"""Compare with self uid."""

result = isinstance(other, Advice) and other._uid == self._uid
result = isinstance(other, Advice) and other.uid == self._uid

return result
2 changes: 1 addition & 1 deletion b3j0f/aop/test/advice.py
Expand Up @@ -27,7 +27,7 @@

from unittest import main

from b3j0f.utils.version import PY2, range
from six import PY2
from b3j0f.utils.ut import UTCase

from ..advice import Advice, weave, unweave, weave_on
Expand Down
3 changes: 2 additions & 1 deletion b3j0f/aop/test/joinpoint.py
Expand Up @@ -28,7 +28,8 @@
from unittest import main

from b3j0f.utils.ut import UTCase
from b3j0f.utils.version import PY3, PY2

from six import PY3, PY2

from ..joinpoint import (
Joinpoint,
Expand Down
6 changes: 6 additions & 0 deletions changelog.rst
@@ -1,6 +1,12 @@
Changelog
=========

0.7.10 (22/09/2015)
-------------------

- add dependency to six.
- add support for python2.5.

0.7.9 (22/09/2015)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -49,7 +49,7 @@
regex = r".*__version__ = '(.*?)'"
VERSION = re_compile(regex, re_S).match(stream).group(1)

DEPENDENCIES = ['b3j0f.utils']
DEPENDENCIES = ['b3j0f.utils', 'six']

KEYWORDS = [
'aspect', 'joinpoint', 'interception', 'interceptor',
Expand Down

0 comments on commit 5101059

Please sign in to comment.