author | Pulkit Goyal <7895pulkit@gmail.com> |
Sat, 16 Apr 2016 03:10:41 +0530 | |
changeset 28930 | e3f01188d439 |
parent 28695 | cc103bd0dbf9 |
child 29933 | 91a95ad985d8 |
permissions | -rw-r--r-- |
27583
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 |
# registrar.py - utilities to register function for specific purpose |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 |
# |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 |
# Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 |
# |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
|
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 |
from __future__ import absolute_import |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 |
|
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 |
from . import ( |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
11 |
util, |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
12 |
) |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
13 |
|
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
14 |
class _funcregistrarbase(object): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
15 |
"""Base of decorator to register a fuction for specific purpose |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
16 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
17 |
This decorator stores decorated functions into own dict 'table'. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
18 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
19 |
The least derived class can be defined by overriding 'formatdoc', |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
20 |
for example:: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
21 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
22 |
class keyword(_funcregistrarbase): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
23 |
_docformat = ":%s: %s" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
24 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
25 |
This should be used as below: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
26 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
27 |
keyword = registrar.keyword() |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
28 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
29 |
@keyword('bar') |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
30 |
def barfunc(*args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
31 |
'''Explanation of bar keyword .... |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
32 |
''' |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
33 |
pass |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
34 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
35 |
In this case: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
36 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
37 |
- 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
38 |
- 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
39 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
40 |
def __init__(self, table=None): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
41 |
if table is None: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
42 |
self._table = {} |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
43 |
else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
44 |
self._table = table |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
45 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
46 |
def __call__(self, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
47 |
return lambda func: self._doregister(func, decl, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
48 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
49 |
def _doregister(self, func, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
50 |
name = self._getname(decl) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
51 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
52 |
if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
53 |
doc = func.__doc__.strip() |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
54 |
func._origdoc = doc |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
55 |
func.__doc__ = self._formatdoc(decl, doc) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
56 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
57 |
self._table[name] = func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
58 |
self._extrasetup(name, func, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
59 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
60 |
return func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
61 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
62 |
def _parsefuncdecl(self, decl): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
63 |
"""Parse function declaration and return the name of function in it |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
64 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
65 |
i = decl.find('(') |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
66 |
if i >= 0: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
67 |
return decl[:i] |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
68 |
else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
69 |
return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
70 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
71 |
def _getname(self, decl): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
72 |
"""Return the name of the registered function from decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
73 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
74 |
Derived class should override this, if it allows more |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
75 |
descriptive 'decl' string than just a name. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
76 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
77 |
return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
78 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
79 |
_docformat = None |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
80 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
81 |
def _formatdoc(self, decl, doc): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
82 |
"""Return formatted document of the registered function for help |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
83 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
84 |
'doc' is '__doc__.strip()' of the registered function. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
85 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
86 |
return self._docformat % (decl, doc) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
87 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
88 |
def _extrasetup(self, name, func): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
89 |
"""Execute exra setup for registered function, if needed |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
90 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
91 |
pass |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
92 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
93 |
class revsetpredicate(_funcregistrarbase): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
94 |
"""Decorator to register revset predicate |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
95 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
96 |
Usage:: |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
97 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
98 |
revsetpredicate = registrar.revsetpredicate() |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
99 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
100 |
@revsetpredicate('mypredicate(arg1, arg2[, arg3])') |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
101 |
def mypredicatefunc(repo, subset, x): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
102 |
'''Explanation of this revset predicate .... |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
103 |
''' |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
104 |
pass |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
105 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
106 |
The first string argument is used also in online help. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
107 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
108 |
Optional argument 'safe' indicates whether a predicate is safe for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
109 |
DoS attack (False by default). |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
110 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
111 |
'revsetpredicate' instance in example above can be used to |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
112 |
decorate multiple functions. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
113 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
114 |
Decorated functions are registered automatically at loading |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
115 |
extension, if an instance named as 'revsetpredicate' is used for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
116 |
decorating in extension. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
117 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
118 |
Otherwise, explicit 'revset.loadpredicate()' is needed. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
119 |
""" |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
120 |
_getname = _funcregistrarbase._parsefuncdecl |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
121 |
_docformat = "``%s``\n %s" |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
122 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
123 |
def _extrasetup(self, name, func, safe=False): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
124 |
func._safe = safe |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
125 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
126 |
class filesetpredicate(_funcregistrarbase): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
127 |
"""Decorator to register fileset predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
128 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
129 |
Usage:: |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
130 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
131 |
filesetpredicate = registrar.filesetpredicate() |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
132 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
133 |
@filesetpredicate('mypredicate()') |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
134 |
def mypredicatefunc(mctx, x): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
135 |
'''Explanation of this fileset predicate .... |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
136 |
''' |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
137 |
pass |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
138 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
139 |
The first string argument is used also in online help. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
140 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
141 |
Optional argument 'callstatus' indicates whether a predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
142 |
implies 'matchctx.status()' at runtime or not (False, by |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
143 |
default). |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
144 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
145 |
Optional argument 'callexisting' indicates whether a predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
146 |
implies 'matchctx.existing()' at runtime or not (False, by |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
147 |
default). |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
148 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
149 |
'filesetpredicate' instance in example above can be used to |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
150 |
decorate multiple functions. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
151 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
152 |
Decorated functions are registered automatically at loading |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
153 |
extension, if an instance named as 'filesetpredicate' is used for |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
154 |
decorating in extension. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
155 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
156 |
Otherwise, explicit 'fileset.loadpredicate()' is needed. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
157 |
""" |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
158 |
_getname = _funcregistrarbase._parsefuncdecl |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
159 |
_docformat = "``%s``\n %s" |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
160 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
161 |
def _extrasetup(self, name, func, callstatus=False, callexisting=False): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
162 |
func._callstatus = callstatus |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
163 |
func._callexisting = callexisting |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
164 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
165 |
class _templateregistrarbase(_funcregistrarbase): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
166 |
"""Base of decorator to register functions as template specific one |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
167 |
""" |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
168 |
_docformat = ":%s: %s" |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
169 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
170 |
class templatekeyword(_templateregistrarbase): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
171 |
"""Decorator to register template keyword |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
172 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
173 |
Usage:: |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
174 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
175 |
templaetkeyword = registrar.templatekeyword() |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
176 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
177 |
@templatekeyword('mykeyword') |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
178 |
def mykeywordfunc(repo, ctx, templ, cache, revcache, **args): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
179 |
'''Explanation of this template keyword .... |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
180 |
''' |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
181 |
pass |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
182 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
183 |
The first string argument is used also in online help. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
184 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
185 |
'templatekeyword' instance in example above can be used to |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
186 |
decorate multiple functions. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
187 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
188 |
Decorated functions are registered automatically at loading |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
189 |
extension, if an instance named as 'templatekeyword' is used for |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
190 |
decorating in extension. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
191 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
192 |
Otherwise, explicit 'templatekw.loadkeyword()' is needed. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
193 |
""" |
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
194 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
195 |
class templatefilter(_templateregistrarbase): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
196 |
"""Decorator to register template filer |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
197 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
198 |
Usage:: |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
199 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
200 |
templatefilter = registrar.templatefilter() |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
201 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
202 |
@templatefilter('myfilter') |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
203 |
def myfilterfunc(text): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
204 |
'''Explanation of this template filter .... |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
205 |
''' |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
206 |
pass |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
207 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
208 |
The first string argument is used also in online help. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
209 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
210 |
'templatefilter' instance in example above can be used to |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
211 |
decorate multiple functions. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
212 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
213 |
Decorated functions are registered automatically at loading |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
214 |
extension, if an instance named as 'templatefilter' is used for |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
215 |
decorating in extension. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
216 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
217 |
Otherwise, explicit 'templatefilters.loadkeyword()' is needed. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
218 |
""" |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
219 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
220 |
class templatefunc(_templateregistrarbase): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
221 |
"""Decorator to register template function |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
222 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
223 |
Usage:: |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
224 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
225 |
templatefunc = registrar.templatefunc() |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
226 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
227 |
@templatefunc('myfunc(arg1, arg2[, arg3])') |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
228 |
def myfuncfunc(context, mapping, args): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
229 |
'''Explanation of this template function .... |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
230 |
''' |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
231 |
pass |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
232 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
233 |
The first string argument is used also in online help. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
234 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
235 |
'templatefunc' instance in example above can be used to |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
236 |
decorate multiple functions. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
237 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
238 |
Decorated functions are registered automatically at loading |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
239 |
extension, if an instance named as 'templatefunc' is used for |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
240 |
decorating in extension. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
241 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
242 |
Otherwise, explicit 'templater.loadfunction()' is needed. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
243 |
""" |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
244 |
_getname = _funcregistrarbase._parsefuncdecl |