*** empty log message ***
[pli.git] / pli / tags / utils.py
blob49abc7fd792b2bf11779dc27c69f458a5a46b101
1 #=======================================================================
3 __version__ = '''0.0.01'''
4 __sub_version__ = '''20071106153539'''
5 __copyright__ = '''(c) Alex A. Naanou 2003'''
8 #-----------------------------------------------------------------------
9 #-----------------------------------------------------------taggerfor---
10 def taggerfor(tagset):
11 '''
12 this will create a decorator for tagging objects within a given tagset.
14 usage:
15 tag = taggerfor(sometagset)
17 @tag('a', 'b', 'c')
18 def func():
19 pass
21 # this is sugar for:
22 def func():
23 pass
24 soemtagset.tag(func, 'a', 'b', 'c')
25 '''
26 def tag(*tags):
27 def _tag(func):
28 tagset.tag(func, *tags)
29 return func
30 return _tag
31 tag.__doc__ = 'decorator, will tag the function with tags within tagset (%s).' % (tagset,)
32 return tag
35 #--------------------------------------------------TagByPathDecorator---
36 class TagByPathDecorator(object):
37 '''
38 path tagging decorator generator.
40 usage:
41 tags = TagByPathDecorator(soemtagset)
43 @tags.a.b.c
44 def func():
45 pass
47 # the above is the same as...
48 @tags.a
49 @tags.b
50 @tags.c
51 def func():
52 pass
54 # this is sugar for:
55 def func():
56 pass
57 soemtagset.tag(func, 'a', 'b', 'c')
58 '''
59 def __init__(self, tagset, path=()):
60 '''
61 '''
62 self._tagset = tagset
63 self._path = path
64 def __getattr__(self, name):
65 '''
66 '''
67 return self.__class__(self._tagset, self._path + (name,))
68 def __call__(self, func):
69 '''
70 '''
71 self._tagset.tag(func, *self._path)
72 return func
76 #=======================================================================
77 # vim:set ts=4 sw=4 nowrap :