text stringlengths 0 828 |
|---|
return data" |
3844,"def get_callable_signature_as_string(the_callable): |
""""""Return a string representing a callable. |
It is executed as if it would have been declared on the prompt. |
>>> def foo(arg1, arg2, arg3='val1', arg4='val2', *args, **argd): |
... pass |
>>> get_callable_signature_as_string(foo) |
def foo(arg1, arg2, arg3='val1', arg4='val2', *args, **argd) |
:param the_callable: the callable to be analyzed. |
:type the_callable: function/callable. |
:return: the signature. |
"""""" |
args, varargs, varkw, defaults = inspect.getargspec(the_callable) |
tmp_args = list(args) |
args_dict = {} |
if defaults: |
defaults = list(defaults) |
else: |
defaults = [] |
while defaults: |
args_dict[tmp_args.pop()] = defaults.pop() |
while tmp_args: |
args_dict[tmp_args.pop()] = None |
args_list = [] |
for arg in args: |
if args_dict[arg] is not None: |
args_list.append(""%s=%s"" % (arg, repr(args_dict[arg]))) |
else: |
args_list.append(arg) |
if varargs: |
args_list.append(""*%s"" % varargs) |
if varkw: |
args_list.append(""**%s"" % varkw) |
args_string = ', '.join(args_list) |
return ""def %s(%s)"" % (the_callable.__name__, args_string)" |
3845,"def get_callable_documentation(the_callable): |
""""""Return a string with the callable signature and its docstring. |
:param the_callable: the callable to be analyzed. |
:type the_callable: function/callable. |
:return: the signature. |
"""""" |
return wrap_text_in_a_box( |
title=get_callable_signature_as_string(the_callable), |
body=(getattr(the_callable, '__doc__') or 'No documentation').replace( |
'\n', '\n\n'), |
style='ascii_double')" |
3846,"def register_extension_class(ext, base, *args, **kwargs): |
""""""Instantiate the given extension class and register as a public attribute of the given base. |
README: The expected protocol here is to instantiate the given extension and pass the base |
object as the first positional argument, then unpack args and kwargs as additional arguments to |
the extension's constructor. |
"""""" |
ext_instance = ext.plugin(base, *args, **kwargs) |
setattr(base, ext.name.lstrip('_'), ext_instance)" |
3847,"def register_extension_method(ext, base, *args, **kwargs): |
""""""Register the given extension method as a public attribute of the given base. |
README: The expected protocol here is that the given extension method is an unbound function. |
It will be bound to the specified base as a method, and then set as a public attribute of that |
base. |
"""""" |
bound_method = create_bound_method(ext.plugin, base) |
setattr(base, ext.name.lstrip('_'), bound_method)" |
3848,"def token_auto_auth(func): |
""""""Wrap class methods with automatic token re-authentication. |
This wrapper will detect authentication failures coming from its wrapped method. When one is |
caught, it will request a new token, and simply replay the original request. |
The one constraint that this wrapper has is that the wrapped method's class must have the |
:py:class:`objectrocket.client.Client` object embedded in it as the property ``_client``. Such |
is the design of all current client operations layers. |
"""""" |
@functools.wraps(func) |
def wrapper(self, *args, **kwargs): |
try: |
response = func(self, *args, **kwargs) |
# If auth failure occurs, attempt to re-authenticate and replay once at most. |
except errors.AuthFailure: |
# Request to have authentication refreshed. |
self._client.auth._refresh() |
# Replay original request. |
response = func(self, *args, **kwargs) |
return response |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.