text stringlengths 0 828 |
|---|
Usage: |
%(std_usage)s |
Options: |
%(std_options)s"""""") |
help_line = ("" %%-%ds %%s"" |
% (max([5] + [len(a) for a in subcmds]), )) |
env[""actions""] = ""\n"".join( |
help_line % ( |
name, |
get_help(subcmd, subcmd_env(env, name), {}).split(""\n"")[0]) |
for name, subcmd in subcmds.items()) |
env[""actions_help""] = """" if not env[""actions""] else ( |
""ACTION could be one of:\n\n"" |
""%(actions)s\n\n"" |
""See '%(surcmd)s help ACTION' for more information "" |
""on a specific command."" |
% env) |
if ""%(std_usage)s"" in doc: |
env[""std_usage""] = txt.indent( |
(""%(surcmd)s --help\n"" |
""%(surcmd)s --version"" + |
((""\n%(surcmd)s help [COMMAND]"" |
""\n%(surcmd)s ACTION [ARGS...]"") if subcmds else """")) |
% env, |
_find_prefix(doc, ""%(std_usage)s""), |
first="""") |
if ""%(std_options)s"" in doc: |
env[""std_options""] = txt.indent( |
""--help Show this screen.\n"" |
""--version Show version."", |
_find_prefix(doc, ""%(std_options)s""), |
first="""") |
if subcmds and ""%(actions_help)s"" not in doc: |
doc += ""\n\n%(actions_help)s"" |
try: |
output = doc % env |
except KeyError as e: |
msg.err(""Doc interpolation of %s needed missing key %r"" |
% (aformat(env[""surcmd""], attrs=[""bold"", ]), |
e.args[0])) |
exit(1) |
except Exception as e: |
msg.err( |
""Documentation of %s is not valid. Please check it:\n%s"" |
% (aformat(env[""surcmd""], attrs=[""bold"", ]), |
doc)) |
exit(1) |
return output" |
221,"def get_calling_prototype(acallable): |
""""""Returns actual working calling prototype |
This means that the prototype given can be used directly |
in the same way by bound method, method, function, lambda:: |
>>> def f1(a, b, c=1): pass |
>>> get_calling_prototype(f1) |
(['a', 'b', 'c'], (1,)) |
>>> get_calling_prototype(lambda a, b: None) |
(['a', 'b'], ()) |
>>> get_calling_prototype(lambda a=None: None) |
(['a'], (None,)) |
>>> get_calling_prototype(lambda : None) |
([], ()) |
>>> class A(object): |
... def m1(self, a, b, c=None): pass |
... @classmethod |
... def cm(cls, a, b, c=None): pass |
... @staticmethod |
... def st(a, b, c=None): pass |
... def __call__(self, a, b, c=None): pass |
>>> get_calling_prototype(A.m1) |
(['self', 'a', 'b', 'c'], (None,)) |
>>> A.m1(A(), 1, 2, 3) |
>>> get_calling_prototype(A().m1) |
(['a', 'b', 'c'], (None,)) |
>>> get_calling_prototype(A.cm) |
(['a', 'b', 'c'], (None,)) |
>>> get_calling_prototype(A().cm) |
(['a', 'b', 'c'], (None,)) |
>>> get_calling_prototype(A.st) |
(['a', 'b', 'c'], (None,)) |
>>> get_calling_prototype(A().st) |
(['a', 'b', 'c'], (None,)) |
>>> get_calling_prototype(A()) |
(['a', 'b', 'c'], (None,)) |
"""""" |
assert callable(acallable) |
if inspect.ismethod(acallable) or inspect.isfunction(acallable): |
args, vargs, vkwargs, defaults = inspect.getargspec(acallable) |
elif not inspect.isfunction(acallable) and hasattr(acallable, ""__call__""): |
## a class instance ? which is callable... |
args, vargs, vkwargs, defaults = inspect.getargspec(acallable.__call__) |
## remove the 'self' argument |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.