text
stringlengths 0
828
|
|---|
1087,"def add_to_sys_modules(mod_name, mod_obj=None):
|
""""""Add a module object to `sys.modules`.
|
@param mod_name: module name, used as key to `sys.modules`.
|
If `mod_name` is `a.b.c` while modules `a` and `a.b` are not existing,
|
empty modules will be created for `a` and `a.b` as well.
|
@param mod_obj: a module object.
|
If None, an empty module object will be created.
|
""""""
|
mod_snames = mod_name.split('.')
|
parent_mod_name = ''
|
parent_mod_obj = None
|
for mod_sname in mod_snames:
|
if parent_mod_name == '':
|
current_mod_name = mod_sname
|
else:
|
current_mod_name = parent_mod_name + '.' + mod_sname
|
if current_mod_name == mod_name:
|
current_mod_obj = mod_obj
|
else:
|
current_mod_obj = sys.modules.get(current_mod_name, None)
|
if current_mod_obj is None:
|
current_mod_obj = imp.new_module(current_mod_name)
|
sys.modules[current_mod_name] = current_mod_obj
|
if parent_mod_obj is not None:
|
setattr(parent_mod_obj, mod_sname, current_mod_obj)
|
parent_mod_name = current_mod_name
|
parent_mod_obj = current_mod_obj"
|
1088,"def split_uri(uri, mod_attr_sep='::'):
|
""""""Split given URI into a tuple of (protocol, module URI, attribute chain).
|
@param mod_attr_sep: the separator between module name and attribute name.
|
""""""
|
uri_parts = uri.split(mod_attr_sep, 1)
|
if len(uri_parts) == 2:
|
mod_uri, attr_chain = uri_parts
|
else:
|
mod_uri = uri_parts[0]
|
attr_chain = None
|
if mod_uri.startswith('py://'):
|
protocol = 'py'
|
mod_uri = mod_uri[5:]
|
elif mod_uri.startswith('file://'):
|
protocol = 'file'
|
mod_uri = mod_uri[7:]
|
# If no protocol prefix is present, and the uri ends with `.py`, then
|
# consider the uri as module file path instead of module name.
|
elif mod_uri.endswith('.py'):
|
protocol = 'file'
|
else:
|
protocol = 'py'
|
info = (protocol, mod_uri, attr_chain)
|
return info"
|
1089,"def get_attr_chain(obj, attr_chain, sep='.'):
|
""""""Get the last attribute of given attribute chain.
|
E.g. `get_attr_chain(x, 'a.b.c')` is equivalent to `x.a.b.c`.
|
@param obj: an object
|
@param attr_chain: a chain of attribute names
|
@param sep: separator for the chain of attribute names
|
""""""
|
if sep is None:
|
sep = '.'
|
attr_names = attr_chain.split(sep)
|
new_obj = obj
|
for attr_name in attr_names:
|
new_obj = getattr(new_obj, attr_name)
|
return new_obj"
|
1090,"def is_closed(self):
|
""""""
|
_check if the observation table is closed.
|
Args:
|
None
|
Returns:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.