Mercurial > hgsubversion
annotate hgsubversion/compathacks.py @ 1506:332e803044e5
commands: fix registrar check
'util' in hgsubversion is a different type from hgutil, which is the one from
core hg. This was hidden by the fallback logic, but I'm not sure why it didn't
cause errors in the tests. Maybe I ran the original tests against an older hg.
This time I've ensured the tests pass against the latest version of hg.
author | Durham Goode <durham@fb.com> |
---|---|
date | Tue, 23 May 2017 11:08:42 -0700 |
parents | c5b7fb8911c0 |
children | 8410a978c650 |
rev | line source |
---|---|
1139
d1bd52202c6d
compathacks: specify for generic compatibility hacks
Sean Farley <sean.michael.farley@gmail.com>
parents:
1138
diff
changeset
|
1 """Functions to work around API changes.""" |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
3 import errno |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
4 import sys |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 |
1405
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
6 from mercurial import util |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
7 |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 def branchset(repo): |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
9 """Return the set of branches present in a repo. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
10 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
11 Works around branchtags() vanishing between 2.8 and 2.9. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
12 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
13 try: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
14 return set(repo.branchmap()) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
15 except AttributeError: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
16 return set(repo.branchtags()) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
17 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
18 def pickle_load(f): |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
19 import cPickle as pickle |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
20 f.seek(0) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
21 return pickle.load(f) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
22 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
23 def makememfilectx(repo, path, data, islink, isexec, copied): |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
24 """Return a memfilectx |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
25 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
26 Works around memfilectx() adding a repo argument between 3.0 and 3.1. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
27 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
28 from mercurial import context |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
29 try: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
30 return context.memfilectx(repo, path, data, islink, isexec, copied) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
31 except TypeError: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
32 return context.memfilectx(path, data, islink, isexec, copied) |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
33 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
34 def filectxfn_deleted(memctx, path): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
35 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
36 Return None or raise an IOError as necessary if path is deleted. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
37 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
38 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
39 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
40 if path_missing: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
41 return compathacks.filectxfn_deleted(memctx, path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
42 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
43 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
44 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
45 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
46 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
47 if getattr(memctx, '_returnnoneformissingfiles', False): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
48 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
49 raise IOError(errno.ENOENT, '%s is deleted' % path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
50 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
51 def filectxfn_deleted_reraise(memctx): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
52 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
53 Return None or reraise exc as necessary. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
54 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
55 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
56 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
57 try: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
58 # code that raises IOError if the path is missing |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
59 except IOError: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
60 return compathacks.filectxfn_deleted_reraise(memctx) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
61 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
62 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
63 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
64 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
65 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
66 exc_info = sys.exc_info() |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
67 if (exc_info[1].errno == errno.ENOENT and |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
68 getattr(memctx, '_returnnoneformissingfiles', False)): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
69 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
70 # preserve traceback info |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
71 raise exc_info[0], exc_info[1], exc_info[2] |
1405
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
72 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
73 # copied from hg 3.8 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
74 class _funcregistrarbase(object): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
75 """Base of decorator to register a fuction for specific purpose |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
76 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
77 This decorator stores decorated functions into own dict 'table'. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
78 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
79 The least derived class can be defined by overriding 'formatdoc', |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
80 for example:: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
81 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
82 class keyword(_funcregistrarbase): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
83 _docformat = ":%s: %s" |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
84 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
85 This should be used as below: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
86 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
87 keyword = registrar.keyword() |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
88 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
89 @keyword('bar') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
90 def barfunc(*args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
91 '''Explanation of bar keyword .... |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
92 ''' |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
93 pass |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
94 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
95 In this case: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
96 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
97 - 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
98 - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
99 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
100 def __init__(self, table=None): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
101 if table is None: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
102 self._table = {} |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
103 else: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
104 self._table = table |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
105 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
106 def __call__(self, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
107 return lambda func: self._doregister(func, decl, *args, **kwargs) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
108 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
109 def _doregister(self, func, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
110 name = self._getname(decl) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
111 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
112 if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
113 doc = func.__doc__.strip() |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
114 func._origdoc = doc |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
115 func.__doc__ = self._formatdoc(decl, doc) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
116 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
117 self._table[name] = func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
118 self._extrasetup(name, func, *args, **kwargs) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
119 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
120 return func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
121 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
122 def _parsefuncdecl(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
123 """Parse function declaration and return the name of function in it |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
124 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
125 i = decl.find('(') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
126 if i >= 0: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
127 return decl[:i] |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
128 else: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
129 return decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
130 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
131 def _getname(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
132 """Return the name of the registered function from decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
133 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
134 Derived class should override this, if it allows more |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
135 descriptive 'decl' string than just a name. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
136 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
137 return decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
138 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
139 _docformat = None |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
140 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
141 def _formatdoc(self, decl, doc): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
142 """Return formatted document of the registered function for help |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
143 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
144 'doc' is '__doc__.strip()' of the registered function. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
145 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
146 return self._docformat % (decl, doc) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
147 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
148 def _extrasetup(self, name, func): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
149 """Execute exra setup for registered function, if needed |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
150 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
151 pass |