Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 21797:b009dd135aa0
hook: restore use of callable() since it was readded in Python 3.2
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 23 Jun 2014 09:24:38 -0400 |
parents | 5bd6a9fec103 |
children | 0fd3862ef425 cdbb85489c41 |
comparison
equal
deleted
inserted
replaced
21796:8225bb1f0ad3 | 21797:b009dd135aa0 |
---|---|
17 | 17 |
18 reason for "true" meaning "hook failed" is so that | 18 reason for "true" meaning "hook failed" is so that |
19 unmodified commands (e.g. mercurial.commands.update) can | 19 unmodified commands (e.g. mercurial.commands.update) can |
20 be run as hooks without wrappers to convert return values.''' | 20 be run as hooks without wrappers to convert return values.''' |
21 | 21 |
22 if util.safehasattr(funcname, '__call__'): | 22 if callable(funcname): |
23 obj = funcname | 23 obj = funcname |
24 funcname = obj.__module__ + "." + obj.__name__ | 24 funcname = obj.__module__ + "." + obj.__name__ |
25 else: | 25 else: |
26 d = funcname.rfind('.') | 26 d = funcname.rfind('.') |
27 if d == -1: | 27 if d == -1: |
68 obj = getattr(obj, p) | 68 obj = getattr(obj, p) |
69 except AttributeError: | 69 except AttributeError: |
70 raise util.Abort(_('%s hook is invalid ' | 70 raise util.Abort(_('%s hook is invalid ' |
71 '("%s" is not defined)') % | 71 '("%s" is not defined)') % |
72 (hname, funcname)) | 72 (hname, funcname)) |
73 if not util.safehasattr(obj, '__call__'): | 73 if not callable(obj): |
74 raise util.Abort(_('%s hook is invalid ' | 74 raise util.Abort(_('%s hook is invalid ' |
75 '("%s" is not callable)') % | 75 '("%s" is not callable)') % |
76 (hname, funcname)) | 76 (hname, funcname)) |
77 | 77 |
78 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) | 78 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) |
115 ui.note(_("running hook %s: %s\n") % (name, cmd)) | 115 ui.note(_("running hook %s: %s\n") % (name, cmd)) |
116 | 116 |
117 starttime = time.time() | 117 starttime = time.time() |
118 env = {} | 118 env = {} |
119 for k, v in args.iteritems(): | 119 for k, v in args.iteritems(): |
120 if util.safehasattr(v, '__call__'): | 120 if callable(v): |
121 v = v() | 121 v = v() |
122 if isinstance(v, dict): | 122 if isinstance(v, dict): |
123 # make the dictionary element order stable across Python | 123 # make the dictionary element order stable across Python |
124 # implementations | 124 # implementations |
125 v = ('{' + | 125 v = ('{' + |
182 os.dup2(stderrno, stdoutno) | 182 os.dup2(stderrno, stdoutno) |
183 except (OSError, AttributeError): | 183 except (OSError, AttributeError): |
184 # files seem to be bogus, give up on redirecting (WSGI, etc) | 184 # files seem to be bogus, give up on redirecting (WSGI, etc) |
185 pass | 185 pass |
186 | 186 |
187 if util.safehasattr(cmd, '__call__'): | 187 if callable(cmd): |
188 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r | 188 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
189 elif cmd.startswith('python:'): | 189 elif cmd.startswith('python:'): |
190 if cmd.count(':') >= 2: | 190 if cmd.count(':') >= 2: |
191 path, cmd = cmd[7:].rsplit(':', 1) | 191 path, cmd = cmd[7:].rsplit(':', 1) |
192 path = util.expandpath(path) | 192 path = util.expandpath(path) |