signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
@app.route('<STR_LIT>', methods=['<STR_LIT:POST>'])<EOL>def slack_message():
|
<EOL>if request.form['<STR_LIT>'] != SLACK_TOKEN:<EOL><INDENT>return ('<STR_LIT>'<EOL>'<STR_LIT>', <NUM_LIT>)<EOL><DEDENT>text = request.form['<STR_LIT:text>']<EOL>user_name = request.form['<STR_LIT>']<EOL>channel_name = request.form['<STR_LIT>']<EOL>card = make_trello_card(name='<STR_LIT>'.format(text=text, user_name=user_name))<EOL>send_slack_message(channel='<STR_LIT>'.format(channel_name=channel_name),<EOL>text='<STR_LIT>'<EOL>.format(url=card.url, text=text, user_name=user_name))<EOL>return '<STR_LIT>'<EOL>
|
When we receive a message from Slack, generate a Trello card and reply
|
f9640:m1
|
def get_func(func_name, module_pathname):
|
if sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3>:<EOL><INDENT>if sys.version_info[<NUM_LIT:1>] >= <NUM_LIT:6>:<EOL><INDENT>import importlib.util<EOL>spec = importlib.util.spec_from_file_location('<STR_LIT>', module_pathname)<EOL>cells_module = importlib.util.module_from_spec(spec)<EOL>spec.loader.exec_module(cells_module)<EOL>return getattr(cells_module, func_name)<EOL><DEDENT>elif sys.version_info[<NUM_LIT:1>] >= <NUM_LIT:4>:<EOL><INDENT>import importlib.machinery<EOL>module = importlib.machinery.SourceFileLoader('<STR_LIT>', module_pathname).load_module()<EOL>return getattr(module, func_name)<EOL><DEDENT><DEDENT>fatal('<STR_LIT>'.format(sys.version))<EOL>
|
Get function from module
:param func_name: function name
:param module_pathname: pathname to module
:return:
|
f9642:m0
|
def fatal(msg):
|
logging.fatal('<STR_LIT>'.format(msg))<EOL>print()<EOL>sys.exit(<NUM_LIT:1>)<EOL>
|
Print message and exit
:param msg: message to print
:return:
|
f9642:m1
|
def main():
|
nb = Notebook()<EOL>nb.run()<EOL>
|
Entry point for pynb command
:return:
|
f9643:m0
|
def cell_hash(self, cell, cell_index):
|
s = '<STR_LIT>'.format(uid=self.uid,<EOL>cell=str(cell.source),<EOL>index=cell_index).encode('<STR_LIT:utf-8>')<EOL>hash = hashlib.sha1(s).hexdigest()[:<NUM_LIT:8>]<EOL>return hash<EOL>
|
Compute cell hash based on cell index and cell content
:param cell: cell to be hashed
:param cell_index: cell index
:return: hash string
|
f9643:c0:m1
|
def run_cell(self, cell, cell_index=<NUM_LIT:0>):
|
hash = self.cell_hash(cell, cell_index)<EOL>fname_session = '<STR_LIT>'.format(hash)<EOL>fname_value = '<STR_LIT>'.format(hash)<EOL>cell_snippet = str("<STR_LIT:U+0020>".join(cell.source.split())).strip()[:<NUM_LIT>]<EOL>if self.disable_cache:<EOL><INDENT>logging.info('<STR_LIT>'.format(hash, cell_snippet))<EOL>return super().run_cell(cell, cell_index)<EOL><DEDENT>if not self.ignore_cache:<EOL><INDENT>if self.cache_valid and os.path.isfile(fname_session) and os.path.isfile(fname_value):<EOL><INDENT>logging.info('<STR_LIT>'.format(hash, cell_snippet))<EOL>self.prev_fname_session = fname_session<EOL>with open(fname_value, '<STR_LIT:rb>') as f:<EOL><INDENT>value = dill.load(f)<EOL>return value<EOL><DEDENT><DEDENT><DEDENT>logging.info('<STR_LIT>'.format(hash, cell_snippet))<EOL>self.cache_valid = False<EOL>if self.prev_fname_session:<EOL><INDENT>if self.prev_fname_session_loaded != self.prev_fname_session:<EOL><INDENT>self.session_load(hash, self.prev_fname_session)<EOL><DEDENT><DEDENT>value = super().run_cell(cell, cell_index)<EOL>cached = self.session_dump(cell, hash, fname_session)<EOL>if cached:<EOL><INDENT>self.prev_fname_session_loaded = fname_session<EOL>self.prev_fname_session = fname_session<EOL>logging.debug('<STR_LIT>'.format(hash, fname_value))<EOL>with open(fname_value, '<STR_LIT:wb>') as f:<EOL><INDENT>dill.dump(value, f)<EOL><DEDENT>logging.debug('<STR_LIT>'.format(hash))<EOL><DEDENT>return value<EOL>
|
Run cell with caching
:param cell: cell to run
:param cell_index: cell index (optional)
:return:
|
f9643:c0:m2
|
def session_load(self, hash, fname_session):
|
logging.debug('<STR_LIT>'.format(hash, fname_session))<EOL>inject_code = ['<STR_LIT>',<EOL>'<STR_LIT>'.format(fname_session),<EOL>]<EOL>inject_cell = nbf.v4.new_code_cell('<STR_LIT:\n>'.join(inject_code))<EOL>super().run_cell(inject_cell)<EOL>
|
Load ipython session from file
:param hash: cell hash
:param fname_session: pathname to dumped session
:return:
|
f9643:c0:m3
|
def session_dump(self, cell, hash, fname_session):
|
logging.debug('<STR_LIT>'.format(hash, fname_session))<EOL>inject_code = ['<STR_LIT>',<EOL>'<STR_LIT>'.format(fname_session),<EOL>]<EOL>inject_cell = nbf.v4.new_code_cell('<STR_LIT:\n>'.join(inject_code))<EOL>reply, outputs = super().run_cell(inject_cell)<EOL>errors = list(filter(lambda out: out.output_type == '<STR_LIT:error>', outputs))<EOL>if len(errors):<EOL><INDENT>logging.info('<STR_LIT>'.format(hash))<EOL>logging.debug(<EOL>'<STR_LIT>'.format(hash, CellExecutionError.from_cell_and_msg(cell, errors[<NUM_LIT:0>])))<EOL>self.disable_cache = True<EOL>os.remove(fname_session)<EOL>return False<EOL><DEDENT>return True<EOL>
|
Dump ipython session to file
:param hash: cell hash
:param fname_session: output filename
:return:
|
f9643:c0:m4
|
def __init__(self):
|
self.long_name = '<STR_LIT>'.format(__version__, self.__class__.__name__,<EOL>*sys.version_info[:<NUM_LIT:3>])<EOL>self.parser = argparse.ArgumentParser(description=self.long_name)<EOL>self.nb = nbf.v4.new_notebook()<EOL>self.nb['<STR_LIT>'] = []<EOL>self.cells_name = None<EOL>self.args = None<EOL>
|
Initialize notebook.
|
f9643:c1:m0
|
def add(self, func, **kwargs):
|
params = set(kwargs.keys())<EOL>func_params = set(inspect.getargspec(func).args)<EOL>if '<STR_LIT>' in func_params:<EOL><INDENT>func_params.remove('<STR_LIT>')<EOL><DEDENT>if params != func_params:<EOL><INDENT>fatal('<STR_LIT>'.format(list(params), list(func_params)))<EOL><DEDENT>lines = inspect.getsourcelines(func)[<NUM_LIT:0>][<NUM_LIT:1>:]<EOL>buffer = "<STR_LIT>"<EOL>indent_count = None<EOL>inside_markdown = False<EOL>return_found = False<EOL>for line in lines:<EOL><INDENT>if len(line.strip()) > <NUM_LIT:0>:<EOL><INDENT>if not indent_count:<EOL><INDENT>indent_count = <NUM_LIT:0><EOL>for c in line:<EOL><INDENT>if c not in ['<STR_LIT:U+0020>', '<STR_LIT:\t>']:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>indent_count += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>line = line[indent_count:]<EOL><DEDENT>if not inside_markdown and line.strip() == "<STR_LIT>":<EOL><INDENT>logging.info('<STR_LIT>')<EOL>break<EOL><DEDENT>if line.strip() == "<STR_LIT>": <EOL><INDENT>if len(buffer.strip()) > <NUM_LIT:0>:<EOL><INDENT>if not inside_markdown: <EOL><INDENT>self.add_cell_code(buffer)<EOL><DEDENT>else: <EOL><INDENT>self.add_cell_markdown(buffer)<EOL><DEDENT><DEDENT>buffer = "<STR_LIT>"<EOL>inside_markdown = not inside_markdown<EOL><DEDENT>else:<EOL><INDENT>buffer += line<EOL><DEDENT><DEDENT>if len(buffer.strip()) > <NUM_LIT:0>:<EOL><INDENT>if not inside_markdown:<EOL><INDENT>self.add_cell_code(buffer)<EOL><DEDENT>else:<EOL><INDENT>self.add_cell_markdown(buffer)<EOL><DEDENT><DEDENT>if len(kwargs) > <NUM_LIT:0>:<EOL><INDENT>if len(self.nb['<STR_LIT>']) > <NUM_LIT:0> and self.nb['<STR_LIT>'][<NUM_LIT:0>].cell_type == '<STR_LIT>':<EOL><INDENT>self.add_cell_params(kwargs, <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>self.add_cell_params(kwargs, <NUM_LIT:0>)<EOL><DEDENT><DEDENT>
|
Parse func's function source code as Python and Markdown cells.
:param func: Python function to parse
:param kwargs: variables to inject as first Python cell
:return:
|
f9643:c1:m1
|
def add_cell_params(self, params, pos=None):
|
self.params = params<EOL>cell_str = '<STR_LIT>'<EOL>for k, v in params.items():<EOL><INDENT>cell_str += "<STR_LIT>".format(k, repr(v))<EOL><DEDENT>self.add_cell_code(cell_str, pos)<EOL>
|
Add cell of Python parameters
:param params: parameters to add
:return:
|
f9643:c1:m2
|
def add_cell_footer(self):
|
<EOL>logging.info('<STR_LIT>')<EOL>for cell in self.nb['<STR_LIT>']:<EOL><INDENT>if cell.cell_type == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' in cell.source:<EOL><INDENT>logging.debug('<STR_LIT>')<EOL>return<EOL><DEDENT><DEDENT><DEDENT>m = """<STR_LIT>"""<EOL>self.add_cell_markdown(<EOL>m.format(exec_time=self.exec_time, exec_begin=self.exec_begin_dt, class_name=self.__class__.__name__,<EOL>argv=str(sys.argv), cells_name=self.cells_name))<EOL>
|
Add footer cell
|
f9643:c1:m3
|
def add_cell_markdown(self, cell_str):
|
logging.debug("<STR_LIT>".format(cell_str))<EOL>cell = '<STR_LIT:\n>'.join(cell_str.split('<STR_LIT:\n>'))<EOL>cell = nbf.v4.new_markdown_cell(cell)<EOL>self.nb['<STR_LIT>'].append(cell)<EOL>
|
Add a markdown cell
:param cell_str: markdown text
:return:
|
f9643:c1:m4
|
def add_cell_code(self, cell_str, pos=None):
|
cell_str = cell_str.strip()<EOL>logging.debug("<STR_LIT>".format(cell_str))<EOL>cell = nbf.v4.new_code_cell(cell_str)<EOL>if pos is None:<EOL><INDENT>self.nb['<STR_LIT>'].append(cell)<EOL><DEDENT>else:<EOL><INDENT>self.nb['<STR_LIT>'].insert(pos, cell)<EOL><DEDENT>
|
Add Python cell
:param cell_str: cell content
:return:
|
f9643:c1:m5
|
def process(self, uid, add_footer=False, no_exec=False, disable_cache=False, ignore_cache=False):
|
self.exec_begin = time.perf_counter()<EOL>self.exec_begin_dt = datetime.datetime.now()<EOL>ep = CachedExecutePreprocessor(timeout=None, kernel_name='<STR_LIT>')<EOL>ep.disable_cache = disable_cache<EOL>ep.ignore_cache = ignore_cache<EOL>ep.uid = uid<EOL>if not no_exec:<EOL><INDENT>with warnings.catch_warnings():<EOL><INDENT>warnings.simplefilter("<STR_LIT:ignore>")<EOL>ep.preprocess(self.nb, {'<STR_LIT>': {'<STR_LIT:path>': '<STR_LIT:.>'}})<EOL><DEDENT><DEDENT>self.exec_time = time.perf_counter() - self.exec_begin<EOL>if add_footer:<EOL><INDENT>self.add_cell_footer()<EOL><DEDENT>if not no_exec:<EOL><INDENT>logging.info('<STR_LIT>'.format(self.exec_time))<EOL><DEDENT>return self<EOL>
|
Execute notebook
:return: self
|
f9643:c1:m6
|
def export_ipynb(self, pathname):
|
if pathname == '<STR_LIT:->':<EOL><INDENT>nbf.write(self.nb, sys.__stdout__)<EOL><DEDENT>else:<EOL><INDENT>with codecs.open(pathname, '<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as f:<EOL><INDENT>ret = nbf.write(self.nb, f)<EOL>pass<EOL><DEDENT><DEDENT>logging.info("<STR_LIT>".format(pathname))<EOL>
|
Export notebook to .ipynb file
:param pathname: output filename
:return:
|
f9643:c1:m7
|
def export_html(self, pathname):
|
html_exporter = HTMLExporter()<EOL>(body, resources) = html_exporter.from_notebook_node(self.nb)<EOL>if pathname == '<STR_LIT:->':<EOL><INDENT>sys.__stdout__.write(body)<EOL><DEDENT>else:<EOL><INDENT>with open(pathname, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(body)<EOL><DEDENT><DEDENT>logging.info("<STR_LIT>".format(pathname))<EOL>
|
Export notebook to .html file
:param pathname: output filename
:return:
|
f9643:c1:m8
|
def add_argument(self, *args, **kwargs):
|
self.parser.add_argument(*args, **kwargs)<EOL>
|
Add application argument
:param args: see parser.add_argument
:param kwargs: see parser.add_argument
:return:
|
f9643:c1:m11
|
def set_cells(self, cells_location):
|
if '<STR_LIT::>' in cells_location:<EOL><INDENT>pathname, func_name = cells_location.split('<STR_LIT::>')<EOL><DEDENT>else:<EOL><INDENT>pathname = cells_location<EOL>func_name = '<STR_LIT>'<EOL><DEDENT>check_isfile(pathname)<EOL>try:<EOL><INDENT>self.cells = get_func(func_name, pathname)<EOL><DEDENT>except SyntaxError as e:<EOL><INDENT>fatal(traceback.format_exc(limit=<NUM_LIT:1>))<EOL><DEDENT>return pathname, func_name<EOL>
|
Set self.cells to function :cells in file pathname.py
:param cells_location: cells location, format 'pathname.py:cells'
:return:
|
f9643:c1:m13
|
def parse_args(self, **kwargs):
|
self.parser.add_argument('<STR_LIT>', help='<STR_LIT>', nargs='<STR_LIT:?>')<EOL>self.parser.add_argument('<STR_LIT>', action="<STR_LIT:store_true>", default=False, help='<STR_LIT>')<EOL>self.parser.add_argument('<STR_LIT>', action="<STR_LIT:store_true>", default=False, help='<STR_LIT>')<EOL>self.parser.add_argument('<STR_LIT>', action="<STR_LIT:store_true>", default=False, help='<STR_LIT>')<EOL>self.parser.add_argument('<STR_LIT>', action='<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', default=None, help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', action="<STR_LIT:store_true>", default=False, help='<STR_LIT>')<EOL>self.add_argument('<STR_LIT>', action="<STR_LIT:store_true>", default=False,<EOL>help='<STR_LIT>')<EOL>if len(sys.argv) == <NUM_LIT:1> and self.__class__ == Notebook:<EOL><INDENT>self.parser.print_help()<EOL>print()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>self.args = self.parser.parse_args()<EOL>
|
Parse arguments
:param kwargs: optional params
:return:
|
f9643:c1:m14
|
def get_kernelspec(self, name):
|
ksm = KernelSpecManager()<EOL>kernelspec = ksm.get_kernel_spec(name).to_dict()<EOL>kernelspec['<STR_LIT:name>'] = name<EOL>kernelspec.pop('<STR_LIT>')<EOL>return kernelspec<EOL>
|
Get a kernel specification dictionary given a kernel name
|
f9643:c1:m16
|
def run(self):
|
if not self.args:<EOL><INDENT>self.parse_args()<EOL><DEDENT>if self.args.log_level:<EOL><INDENT>logging.getLogger().setLevel(logging.getLevelName(self.args.log_level))<EOL>logging.debug('<STR_LIT>'.format(self.args.log_level))<EOL><DEDENT>if self.args.import_ipynb:<EOL><INDENT>check_isfile(self.args.import_ipynb)<EOL>logging.info('<STR_LIT>'.format(self.args.import_ipynb))<EOL>self.nb = nbf.read(self.args.import_ipynb, as_version=<NUM_LIT:4>)<EOL>uid = self.args.import_ipynb<EOL><DEDENT>else:<EOL><INDENT>uid = self.load_cells_params()<EOL><DEDENT>logging.debug("<STR_LIT>".format(uid))<EOL>logging.info('<STR_LIT>'.format(self.args.disable_cache))<EOL>logging.info('<STR_LIT>'.format(self.args.ignore_cache))<EOL>if self.args.export_pynb and not self.args.no_exec:<EOL><INDENT>fatal('<STR_LIT>')<EOL><DEDENT>if self.args.kernel:<EOL><INDENT>self.set_kernel(self.args.kernel)<EOL><DEDENT>self.process(uid=uid,<EOL>add_footer=not self.args.disable_footer,<EOL>no_exec=self.args.no_exec,<EOL>disable_cache=self.args.disable_cache,<EOL>ignore_cache=self.args.ignore_cache)<EOL>if self.args.export_html:<EOL><INDENT>self.export_html(self.args.export_html)<EOL><DEDENT>if self.args.export_ipynb:<EOL><INDENT>self.export_ipynb(self.args.export_ipynb)<EOL><DEDENT>if self.args.export_pynb:<EOL><INDENT>self.export_pynb(self.args.export_pynb)<EOL><DEDENT>
|
Run notebook as an application
:param params: parameters to inject in the notebook
:return:
|
f9643:c1:m18
|
def markdown():
|
# Title
|
f9646:m5
|
|
def docker_exec(cmdline):
|
local('<STR_LIT>'.format(cmdline))<EOL>
|
Execute command in running docker container
:param cmdline: command to be executed
|
f9647:m1
|
def inc_version():
|
new_version = version.__version__<EOL>values = list(map(lambda x: int(x), new_version.split('<STR_LIT:.>')))<EOL>values[<NUM_LIT:2>] += <NUM_LIT:1><EOL>with open('<STR_LIT>', '<STR_LIT:w>') as f:<EOL><INDENT>f.write('<STR_LIT>'.format(values[<NUM_LIT:0>], values[<NUM_LIT:1>], values[<NUM_LIT:2>]))<EOL><DEDENT>with open('<STR_LIT>', '<STR_LIT:w>') as f:<EOL><INDENT>f.write('<STR_LIT>'.format(values[<NUM_LIT:0>], values[<NUM_LIT:1>], values[<NUM_LIT:2>]))<EOL><DEDENT>importlib.reload(version)<EOL>print('<STR_LIT>'.format(version.__version__))<EOL>return values<EOL>
|
Increment micro release version (in 'major.minor.micro') in version.py and re-import it.
Major and minor versions must be incremented manually in version.py.
:return: list with current version numbers, e.g., [0,1,23].
|
f9647:m2
|
@task<EOL>def git_check():
|
<EOL>output = local('<STR_LIT>',<EOL>capture=True).strip()<EOL>if output:<EOL><INDENT>fatal('<STR_LIT>'.format(output))<EOL><DEDENT>output = local('<STR_LIT>',<EOL>capture=True).strip()<EOL>if output:<EOL><INDENT>fatal('<STR_LIT>'.format(output))<EOL><DEDENT>
|
Check that all changes , besides versioning files, are committed
:return:
|
f9647:m3
|
def git_push():
|
<EOL>new_version = version.__version__<EOL>values = list(map(lambda x: int(x), new_version.split('<STR_LIT:.>')))<EOL>local('<STR_LIT>')<EOL>local('<STR_LIT>')<EOL>local('<STR_LIT>'.format(values[<NUM_LIT:0>], values[<NUM_LIT:1>], values[<NUM_LIT:2>]))<EOL>local('<STR_LIT>')<EOL>local('<STR_LIT>')<EOL>
|
Push new version and corresponding tag to origin
:return:
|
f9647:m4
|
@task<EOL>def docker_build(options='<STR_LIT>'):
|
local('<STR_LIT>'.format(options))<EOL>
|
Build docker image
|
f9647:m5
|
@task<EOL>def docker_start(develop=True):
|
curr_dir = os.path.dirname(os.path.realpath(__file__))<EOL>local('<STR_LIT>'.format(curr_dir))<EOL>if develop:<EOL><INDENT>docker_exec('<STR_LIT>')<EOL><DEDENT>print('<STR_LIT>')<EOL>
|
Start docker container
|
f9647:m6
|
@task<EOL>def docker_stop():
|
local('<STR_LIT>')<EOL>
|
Stop docker container
|
f9647:m7
|
@task<EOL>def docker_sh():
|
docker_exec('<STR_LIT>')<EOL>
|
Execute command in docker container
|
f9647:m8
|
@task<EOL>def fix_pep8():
|
docker_exec('<STR_LIT>')<EOL>
|
Fix a few common and easy PEP8 mistakes in docker container
|
f9647:m13
|
@task<EOL>def build():
|
docker_exec('<STR_LIT>')<EOL>
|
Build package in docker container
:return:
|
f9647:m14
|
@task<EOL>def release():
|
from secrets import pypi_auth<EOL>git_check()<EOL>test()<EOL>inc_version()<EOL>git_push()<EOL>build()<EOL>pathname = '<STR_LIT>'.format(version.__version__)<EOL>docker_exec('<STR_LIT>'.format(pathname=pathname, **pypi_auth))<EOL>clean()<EOL>
|
Release new package version to pypi
:return:
|
f9647:m15
|
@task<EOL>def clean():
|
local('<STR_LIT>')<EOL>
|
Rempove temporary files
|
f9647:m16
|
def cells():
|
import time<EOL>def query_db():<EOL><INDENT>time.sleep(<NUM_LIT:5>)<EOL>return [<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>, <NUM_LIT:5>]<EOL><DEDENT>def clean(data):<EOL><INDENT>time.sleep(<NUM_LIT:2>)<EOL>return [x for x in data if x % <NUM_LIT:2> == <NUM_LIT:0>]<EOL><DEDENT>def myfilter(data):<EOL><INDENT>time.sleep(<NUM_LIT:2>)<EOL>return [x for x in data if x >= <NUM_LIT:3>]<EOL><DEDENT>'''<STR_LIT:U+0020>'''<EOL>rows = query_db()<EOL>'''<STR_LIT:U+0020>'''<EOL>data = clean(rows)<EOL>'''<STR_LIT:U+0020>'''<EOL>data, len(data)<EOL>
|
# Slow
|
f9648:m0
|
def cells(a, b):
|
a, b = int(a), int(b)<EOL>'''<STR_LIT:U+0020>'''<EOL>a + b<EOL>
|
# Sum
|
f9651:m0
|
def parse_pgurl(self, url):
|
parsed = urlsplit(url)<EOL>return {<EOL>'<STR_LIT:user>': parsed.username,<EOL>'<STR_LIT:password>': parsed.password,<EOL>'<STR_LIT>': parsed.path.lstrip('<STR_LIT:/>'),<EOL>'<STR_LIT:host>': parsed.hostname,<EOL>'<STR_LIT:port>': parsed.port or <NUM_LIT>,<EOL>}<EOL>
|
Given a Postgres url, return a dict with keys for user, password,
host, port, and database.
|
f9656:c1:m11
|
def pdist(X):
|
return pairwise_distances(X)[np.triu_indices(X.shape[<NUM_LIT:0>], <NUM_LIT:1>)]<EOL>
|
Condensed pairwise distances, like scipy.spatial.distance.pdist()
|
f9658:m0
|
def imscatter(images, positions):
|
positions = np.array(positions)<EOL>bottoms = positions[:, <NUM_LIT:1>] - np.array([im.shape[<NUM_LIT:1>] / <NUM_LIT> for im in images])<EOL>tops = bottoms + np.array([im.shape[<NUM_LIT:1>] for im in images])<EOL>lefts = positions[:, <NUM_LIT:0>] - np.array([im.shape[<NUM_LIT:0>] / <NUM_LIT> for im in images])<EOL>rigths = lefts + np.array([im.shape[<NUM_LIT:0>] for im in images])<EOL>most_bottom = int(np.floor(bottoms.min()))<EOL>most_top = int(np.ceil(tops.max()))<EOL>most_left = int(np.floor(lefts.min()))<EOL>most_right = int(np.ceil(rigths.max()))<EOL>scatter_image = np.zeros(<EOL>[most_right - most_left, most_top - most_bottom, <NUM_LIT:3>], dtype=imgs[<NUM_LIT:0>].dtype)<EOL>positions -= [most_left, most_bottom]<EOL>for im, pos in zip(images, positions):<EOL><INDENT>xl = int(pos[<NUM_LIT:0>] - im.shape[<NUM_LIT:0>] / <NUM_LIT:2>)<EOL>xr = xl + im.shape[<NUM_LIT:0>]<EOL>yb = int(pos[<NUM_LIT:1>] - im.shape[<NUM_LIT:1>] / <NUM_LIT:2>)<EOL>yt = yb + im.shape[<NUM_LIT:1>]<EOL>scatter_image[xl:xr, yb:yt, :] = im<EOL><DEDENT>return scatter_image<EOL>
|
Creates a scatter plot, where each plot is shown by corresponding image
|
f9664:m0
|
@classmethod<EOL><INDENT>def prepend(cls, d, s, filter=Filter()):<DEDENT>
|
i = <NUM_LIT:0><EOL>for x in s:<EOL><INDENT>if x in filter:<EOL><INDENT>d.insert(i, x)<EOL>i += <NUM_LIT:1><EOL><DEDENT><DEDENT>
|
Prepend schema object's from B{s}ource list to
the B{d}estination list while applying the filter.
@param d: The destination list.
@type d: list
@param s: The source list.
@type s: list
@param filter: A filter that allows items to be prepended.
@type filter: L{Filter}
|
f9667:c0:m0
|
@classmethod<EOL><INDENT>def append(cls, d, s, filter=Filter()):<DEDENT>
|
for item in s:<EOL><INDENT>if item in filter:<EOL><INDENT>d.append(item)<EOL><DEDENT><DEDENT>
|
Append schema object's from B{s}ource list to
the B{d}estination list while applying the filter.
@param d: The destination list.
@type d: list
@param s: The source list.
@type s: list
@param filter: A filter that allows items to be appended.
@type filter: L{Filter}
|
f9667:c0:m1
|
def __init__(self, schema, root):
|
self.schema = schema<EOL>self.root = root<EOL>self.id = objid(self)<EOL>self.name = root.get('<STR_LIT:name>')<EOL>self.qname = (self.name, schema.tns[<NUM_LIT:1>])<EOL>self.min = root.get('<STR_LIT>')<EOL>self.max = root.get('<STR_LIT>')<EOL>self.type = root.get('<STR_LIT:type>')<EOL>self.ref = root.get('<STR_LIT>')<EOL>self.form_qualified = schema.form_qualified<EOL>self.nillable = False<EOL>self.default = root.get('<STR_LIT:default>')<EOL>self.rawchildren = []<EOL>self.cache = {}<EOL>
|
@param schema: The containing schema.
@type schema: L{schema.Schema}
@param root: The xml root node.
@type root: L{Element}
|
f9667:c0:m2
|
def attributes(self, filter=Filter()):
|
result = []<EOL>for child, ancestry in self:<EOL><INDENT>if child.isattr() and child in filter:<EOL><INDENT>result.append((child, ancestry))<EOL><DEDENT><DEDENT>return result<EOL>
|
Get only the attribute content.
@param filter: A filter to constrain the result.
@type filter: L{Filter}
@return: A list of tuples (attr, ancestry)
@rtype: [(L{SchemaObject}, [L{SchemaObject},..]),..]
|
f9667:c0:m3
|
def children(self, filter=Filter()):
|
result = []<EOL>for child, ancestry in self:<EOL><INDENT>if not child.isattr() and child in filter:<EOL><INDENT>result.append((child, ancestry))<EOL><DEDENT><DEDENT>return result<EOL>
|
Get only the I{direct} or non-attribute content.
@param filter: A filter to constrain the result.
@type filter: L{Filter}
@return: A list tuples: (child, ancestry)
@rtype: [(L{SchemaObject}, [L{SchemaObject},..]),..]
|
f9667:c0:m4
|
def get_attribute(self, name):
|
for child, ancestry in self.attributes():<EOL><INDENT>if child.name == name:<EOL><INDENT>return (child, ancestry)<EOL><DEDENT><DEDENT>return (None, [])<EOL>
|
Get (find) a I{non-attribute} attribute by name.
@param name: A attribute name.
@type name: str
@return: A tuple: the requested (attribute, ancestry).
@rtype: (L{SchemaObject}, [L{SchemaObject},..])
|
f9667:c0:m5
|
def get_child(self, name):
|
for child, ancestry in self.children():<EOL><INDENT>if child.any() or child.name == name:<EOL><INDENT>return (child, ancestry)<EOL><DEDENT><DEDENT>return (None, [])<EOL>
|
Get (find) a I{non-attribute} child by name.
@param name: A child name.
@type name: str
@return: A tuple: the requested (child, ancestry).
@rtype: (L{SchemaObject}, [L{SchemaObject},..])
|
f9667:c0:m6
|
def namespace(self, prefix=None):
|
ns = self.schema.tns<EOL>if ns[<NUM_LIT:0>] is None:<EOL><INDENT>ns = (prefix, ns[<NUM_LIT:1>])<EOL><DEDENT>return ns<EOL>
|
Get this properties namespace
@param prefix: The default prefix.
@type prefix: str
@return: The schema's target namespace
@rtype: (I{prefix},I{URI})
|
f9667:c0:m7
|
def unbounded(self):
|
max = self.max<EOL>if max is None:<EOL><INDENT>max = '<STR_LIT:1>'<EOL><DEDENT>if max.isdigit():<EOL><INDENT>return (int(max) > <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>return max == '<STR_LIT>'<EOL><DEDENT>
|
Get whether this node is unbounded I{(a collection)}
@return: True if unbounded, else False.
@rtype: boolean
|
f9667:c0:m9
|
def optional(self):
|
min = self.min<EOL>if min is None:<EOL><INDENT>min = '<STR_LIT:1>'<EOL><DEDENT>return min == '<STR_LIT:0>'<EOL>
|
Get whether this type is optional.
@return: True if optional, else False
@rtype: boolean
|
f9667:c0:m10
|
def required(self):
|
return not self.optional()<EOL>
|
Get whether this type is required.
@return: True if required, else False
@rtype: boolean
|
f9667:c0:m11
|
def resolve(self, nobuiltin=False):
|
return self.cache.get(nobuiltin, self)<EOL>
|
Resolve and return the nodes true self.
@param nobuiltin: Flag indicates that resolution must
not continue to include xsd builtins.
@return: The resolved (true) type.
@rtype: L{SchemaObject}
|
f9667:c0:m12
|
def sequence(self):
|
return False<EOL>
|
Get whether this is an <xs:sequence/>
@return: True if <xs:sequence/>, else False
@rtype: boolean
|
f9667:c0:m13
|
def xslist(self):
|
return False<EOL>
|
Get whether this is an <xs:list/>
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m14
|
def all(self):
|
return False<EOL>
|
Get whether this is an <xs:all/>
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m15
|
def choice(self):
|
return False<EOL>
|
Get whether this is n <xs:choice/>
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m16
|
def any(self):
|
return False<EOL>
|
Get whether this is an <xs:any/>
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m17
|
def builtin(self):
|
return False<EOL>
|
Get whether this is a schema-instance (xs) type.
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m18
|
def enum(self):
|
return False<EOL>
|
Get whether this is a simple-type containing an enumeration.
@return: True if any, else False
@rtype: boolean
|
f9667:c0:m19
|
def isattr(self):
|
return False<EOL>
|
Get whether the object is a schema I{attribute} definition.
@return: True if an attribute, else False.
@rtype: boolean
|
f9667:c0:m20
|
def extension(self):
|
return False<EOL>
|
Get whether the object is an extension of another type.
@return: True if an extension, else False.
@rtype: boolean
|
f9667:c0:m21
|
def restriction(self):
|
return False<EOL>
|
Get whether the object is an restriction of another type.
@return: True if an restriction, else False.
@rtype: boolean
|
f9667:c0:m22
|
def mixed(self):
|
return False<EOL>
|
Get whether this I{mixed} content.
|
f9667:c0:m23
|
def find(self, qref, classes=()):
|
if not len(classes):<EOL><INDENT>classes = (self.__class__,)<EOL><DEDENT>if self.qname == qref and self.__class__ in classes:<EOL><INDENT>return self<EOL><DEDENT>for c in self.rawchildren:<EOL><INDENT>p = c.find(qref, classes)<EOL>if p is not None:<EOL><INDENT>return p<EOL><DEDENT><DEDENT>return None<EOL>
|
Find a referenced type in self or children.
@param qref: A qualified reference.
@type qref: qref
@param classes: A list of classes used to qualify the match.
@type classes: [I{class},...]
@return: The referenced type.
@rtype: L{SchemaObject}
@see: L{qualify()}
|
f9667:c0:m24
|
def translate(self, value, topython=True):
|
return value<EOL>
|
Translate a value (type) to/from a python type.
@param value: A value to translate.
@return: The converted I{language} type.
|
f9667:c0:m25
|
def childtags(self):
|
return ()<EOL>
|
Get a list of valid child tag names.
@return: A list of child tag names.
@rtype: [str,...]
|
f9667:c0:m26
|
def dependencies(self):
|
return (None, [])<EOL>
|
Get a list of dependancies for dereferencing.
@return: A merge dependancy index and a list of dependancies.
@rtype: (int, [L{SchemaObject},...])
|
f9667:c0:m27
|
def autoqualified(self):
|
return ['<STR_LIT:type>', '<STR_LIT>']<EOL>
|
The list of I{auto} qualified attribute values.
Qualification means to convert values into I{qref}.
@return: A list of attibute names.
@rtype: list
|
f9667:c0:m28
|
def qualify(self):
|
defns = self.root.defaultNamespace()<EOL>if Namespace.none(defns):<EOL><INDENT>defns = self.schema.tns<EOL><DEDENT>for a in self.autoqualified():<EOL><INDENT>ref = getattr(self, a)<EOL>if ref is None:<EOL><INDENT>continue<EOL><DEDENT>if isqref(ref):<EOL><INDENT>continue<EOL><DEDENT>qref = qualify(ref, self.root, defns)<EOL>log.debug('<STR_LIT>', self.id, a, ref, qref)<EOL>setattr(self, a, qref)<EOL><DEDENT>
|
Convert attribute values, that are references to other
objects, into I{qref}. Qualfied using default document namespace.
Since many wsdls are written improperly: when the document does
not define a default namespace, the schema target namespace is used
to qualify references.
|
f9667:c0:m29
|
def merge(self, other):
|
other.qualify()<EOL>for n in ('<STR_LIT:name>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT:default>',<EOL>'<STR_LIT:type>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',):<EOL><INDENT>if getattr(self, n) is not None:<EOL><INDENT>continue<EOL><DEDENT>v = getattr(other, n)<EOL>if v is None:<EOL><INDENT>continue<EOL><DEDENT>setattr(self, n, v)<EOL><DEDENT>
|
Merge another object as needed.
|
f9667:c0:m30
|
def content(self, collection=None, filter=Filter(), history=None):
|
if collection is None:<EOL><INDENT>collection = []<EOL><DEDENT>if history is None:<EOL><INDENT>history = []<EOL><DEDENT>if self in history:<EOL><INDENT>return collection<EOL><DEDENT>history.append(self)<EOL>if self in filter:<EOL><INDENT>collection.append(self)<EOL><DEDENT>for c in self.rawchildren:<EOL><INDENT>c.content(collection, filter, history[:])<EOL><DEDENT>return collection<EOL>
|
Get a I{flattened} list of this nodes contents.
@param collection: A list to fill.
@type collection: list
@param filter: A filter used to constrain the result.
@type filter: L{Filter}
@param history: The history list used to prevent cyclic dependency.
@type history: list
@return: The filled list.
@rtype: list
|
f9667:c0:m31
|
def str(self, indent=<NUM_LIT:0>, history=None):
|
if history is None:<EOL><INDENT>history = []<EOL><DEDENT>if self in history:<EOL><INDENT>return '<STR_LIT>' % Repr(self)<EOL><DEDENT>history.append(self)<EOL>tab = '<STR_LIT>' % (indent * <NUM_LIT:3>, '<STR_LIT>')<EOL>result = []<EOL>result.append('<STR_LIT>' % (tab, self.id))<EOL>for n in self.description():<EOL><INDENT>if not hasattr(self, n):<EOL><INDENT>continue<EOL><DEDENT>v = getattr(self, n)<EOL>if v is None:<EOL><INDENT>continue<EOL><DEDENT>result.append('<STR_LIT>' % (n, v))<EOL><DEDENT>if len(self):<EOL><INDENT>result.append('<STR_LIT:>>')<EOL>for c in self.rawchildren:<EOL><INDENT>result.append('<STR_LIT:\n>')<EOL>result.append(c.str(indent+<NUM_LIT:1>, history[:]))<EOL>if c.isattr():<EOL><INDENT>result.append('<STR_LIT:@>')<EOL><DEDENT><DEDENT>result.append('<STR_LIT>' % tab)<EOL>result.append('<STR_LIT>' % self.__class__.__name__)<EOL><DEDENT>else:<EOL><INDENT>result.append('<STR_LIT>')<EOL><DEDENT>return '<STR_LIT>'.join(result)<EOL>
|
Get a string representation of this object.
@param indent: The indent.
@type indent: int
@return: A string.
@rtype: str
|
f9667:c0:m32
|
def description(self):
|
return ()<EOL>
|
Get the names used for str() and repr() description.
@return: A dictionary of relavent attributes.
@rtype: [str,...]
|
f9667:c0:m33
|
def __init__(self, sx):
|
self.stack = []<EOL>self.push(sx)<EOL>
|
@param sx: A schema object.
@type sx: L{SchemaObject}
|
f9667:c1:m0
|
def push(self, sx):
|
self.stack.append(Iter.Frame(sx))<EOL>
|
Create a frame and push the specified object.
@param sx: A schema object to push.
@type sx: L{SchemaObject}
|
f9667:c1:m1
|
def pop(self):
|
if len(self.stack):<EOL><INDENT>return self.stack.pop()<EOL><DEDENT>else:<EOL><INDENT>raise StopIteration()<EOL><DEDENT>
|
Pop the I{top} frame.
@return: The popped frame.
@rtype: L{Frame}
@raise StopIteration: when stack is empty.
|
f9667:c1:m2
|
def top(self):
|
if len(self.stack):<EOL><INDENT>return self.stack[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>raise StopIteration()<EOL><DEDENT>
|
Get the I{top} frame.
@return: The top frame.
@rtype: L{Frame}
@raise StopIteration: when stack is empty.
|
f9667:c1:m3
|
def next(self):
|
frame = self.top()<EOL>while True:<EOL><INDENT>result = frame.next()<EOL>if result is None:<EOL><INDENT>self.pop()<EOL>return self.next()<EOL><DEDENT>if isinstance(result, Content):<EOL><INDENT>ancestry = [f.sx for f in self.stack]<EOL>return (result, ancestry)<EOL><DEDENT>self.push(result)<EOL>return self.next()<EOL><DEDENT>
|
Get the next item.
@return: A tuple: the next (child, ancestry).
@rtype: (L{SchemaObject}, [L{SchemaObject},..])
@raise StopIteration: A the end.
|
f9667:c1:m5
|
def __init__(self, schema, name):
|
root = Element(name)<EOL>SchemaObject.__init__(self, schema, root)<EOL>self.name = name<EOL>self.nillable = True<EOL>
|
@param schema: The containing schema.
@type schema: L{schema.Schema}
|
f9667:c2:m0
|
def __init__(self, matcher, limit=<NUM_LIT:0>):
|
self.matcher = matcher<EOL>self.limit = limit<EOL>
|
@param matcher: An object used as criteria for match.
@type matcher: I{any}.match(n)
@param limit: Limit the number of matches. 0=unlimited.
@type limit: int
|
f9667:c4:m0
|
def find(self, node, list):
|
if self.matcher.match(node):<EOL><INDENT>list.append(node)<EOL>self.limit -= <NUM_LIT:1><EOL>if self.limit == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT><DEDENT>for c in node.rawchildren:<EOL><INDENT>self.find(c, list)<EOL><DEDENT>return self<EOL>
|
Traverse the tree looking for matches.
@param node: A node to match on.
@type node: L{SchemaObject}
@param list: A list to fill.
@type list: list
|
f9667:c4:m1
|
def examine(self, root):
|
pass<EOL>
|
Examine and repair the schema (if necessary).
@param root: A schema root element.
@type root: L{Element}
|
f9668:c0:m0
|
def add(self, doctor):
|
self.doctors.append(doctor)<EOL>
|
Add a doctor to the practice
@param doctor: A doctor to add.
@type doctor: L{Doctor}
|
f9668:c1:m1
|
def __init__(self, *tns):
|
self.tns = []<EOL>self.add(*tns)<EOL>
|
@param tns: A list of target namespaces.
@type tns: [str,...]
|
f9668:c2:m0
|
def add(self, *tns):
|
self.tns += tns<EOL>
|
Add I{targetNamesapces} to be added.
@param tns: A list of target namespaces.
@type tns: [str,...]
|
f9668:c2:m1
|
def match(self, root, ns):
|
tns = root.get('<STR_LIT>')<EOL>if len(self.tns):<EOL><INDENT>matched = tns in self.tns<EOL><DEDENT>else:<EOL><INDENT>matched = <NUM_LIT:1><EOL><DEDENT>itself = ns == tns<EOL>return matched and not itself<EOL>
|
Match by I{targetNamespace} excluding those that
are equal to the specified namespace to prevent
adding an import to itself.
@param root: A schema root.
@type root: L{Element}
|
f9668:c2:m2
|
def __init__(self, ns, location=None):
|
self.ns = ns<EOL>self.location = location<EOL>self.filter = TnsFilter()<EOL>
|
@param ns: An import namespace.
@type ns: str
@param location: An optional I{schemaLocation}.
@type location: str
|
f9668:c3:m0
|
def setfilter(self, filter):
|
self.filter = filter<EOL>
|
Set the filter.
@param filter: A filter to set.
@type filter: L{TnsFilter}
|
f9668:c3:m1
|
def apply(self, root):
|
if not self.filter.match(root, self.ns):<EOL><INDENT>return<EOL><DEDENT>if self.exists(root):<EOL><INDENT>return<EOL><DEDENT>node = Element('<STR_LIT>', ns=self.xsdns)<EOL>node.set('<STR_LIT>', self.ns)<EOL>if self.location is not None:<EOL><INDENT>node.set('<STR_LIT>', self.location)<EOL><DEDENT>log.debug('<STR_LIT>', node)<EOL>root.insert(node)<EOL>
|
Apply the import (rule) to the specified schema.
If the schema does not already contain an import for the
I{namespace} specified here, it is added.
@param root: A schema root.
@type root: L{Element}
|
f9668:c3:m2
|
def add(self, root):
|
node = Element('<STR_LIT>', ns=self.xsdns)<EOL>node.set('<STR_LIT>', self.ns)<EOL>if self.location is not None:<EOL><INDENT>node.set('<STR_LIT>', self.location)<EOL><DEDENT>log.debug('<STR_LIT>', node)<EOL>root.insert(node)<EOL>
|
Add an <xs:import/> to the specified schema root.
@param root: A schema root.
@type root: L{Element}
|
f9668:c3:m3
|
def exists(self, root):
|
for node in root.children:<EOL><INDENT>if node.name != '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>ns = node.get('<STR_LIT>')<EOL>if self.ns == ns:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>
|
Check to see if the <xs:import/> already exists
in the specified schema root by matching I{namesapce}.
@param root: A schema root.
@type root: L{Element}
|
f9668:c3:m4
|
def add(self, *imports):
|
self.imports += imports<EOL>
|
Add a namesapce to be checked.
@param imports: A list of L{Import} objects.
@type imports: [L{Import},..]
|
f9668:c4:m1
|
def qref(self):
|
qref = self.type<EOL>if qref is None and len(self) == <NUM_LIT:0>:<EOL><INDENT>ls = []<EOL>m = RestrictionMatcher()<EOL>finder = NodeFinder(m, <NUM_LIT:1>)<EOL>finder.find(self, ls)<EOL>if len(ls):<EOL><INDENT>return ls[<NUM_LIT:0>].ref<EOL><DEDENT><DEDENT>return qref<EOL>
|
Get the I{type} qualified reference to the referenced xsd type.
This method takes into account simple types defined through
restriction with are detected by determining that self is simple
(len=0) and by finding a restriction child.
@return: The I{type} qualified reference.
@rtype: qref
|
f9669:c1:m1
|
def implany(self):
|
if self.type is None and self.ref is None and self.root.isempty():<EOL><INDENT>self.type = self.anytype()<EOL><DEDENT>return self<EOL>
|
Set the type as any when implicit.
An implicit <xs:any/> is when an element has not
body and no type defined.
@return: self
@rtype: L{Element}
|
f9669:c15:m1
|
def anytype(self):
|
p, u = Namespace.xsdns<EOL>mp = self.root.findPrefix(u)<EOL>if mp is None:<EOL><INDENT>mp = p<EOL>self.root.addPrefix(p, u)<EOL><DEDENT>return '<STR_LIT::>'.join((mp, '<STR_LIT>'))<EOL>
|
create an xsd:anyType reference
|
f9669:c15:m8
|
@classmethod<EOL><INDENT>def bind(cls, ns, location=None):<DEDENT>
|
if location is None:<EOL><INDENT>location = ns<EOL><DEDENT>cls.locations[ns] = location<EOL>
|
Bind a namespace to a schema location (URI).
This is used for imports that don't specify a schemaLocation.
@param ns: A namespace-uri.
@type ns: str
@param location: The (optional) schema location for the
namespace. (default=ns).
@type location: str
|
f9669:c17:m0
|
def open(self, options):
|
if self.opened:<EOL><INDENT>return<EOL><DEDENT>self.opened = True<EOL>log.debug('<STR_LIT>',<EOL>self.id,<EOL>self.ns[<NUM_LIT:1>],<EOL>self.location<EOL>)<EOL>result = self.locate()<EOL>if result is None:<EOL><INDENT>if self.location is None:<EOL><INDENT>log.debug('<STR_LIT>', self.ns[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>result = self.download(options)<EOL><DEDENT><DEDENT>log.debug('<STR_LIT>', result)<EOL>return result<EOL>
|
Open and import the refrenced schema.
@param options: An options dictionary.
@type options: L{options.Options}
@return: The referenced schema.
@rtype: L{Schema}
|
f9669:c17:m2
|
def locate(self):
|
if self.ns[<NUM_LIT:1>] == self.schema.tns[<NUM_LIT:1>]:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return self.schema.locate(self.ns)<EOL><DEDENT>
|
find the schema locally
|
f9669:c17:m3
|
def download(self, options):
|
url = self.location<EOL>try:<EOL><INDENT>if '<STR_LIT>' not in url:<EOL><INDENT>url = urljoin(self.schema.baseurl, url)<EOL><DEDENT>reader = DocumentReader(options)<EOL>d = reader.open(url)<EOL>root = d.root()<EOL>root.set('<STR_LIT:url>', url)<EOL>return self.schema.instance(root, url, options)<EOL><DEDENT>except TransportError:<EOL><INDENT>msg = '<STR_LIT>' % (self.ns[<NUM_LIT:1>], url)<EOL>log.error('<STR_LIT>', self.id, msg, exc_info=True)<EOL>raise Exception(msg)<EOL><DEDENT>
|
download the schema
|
f9669:c17:m4
|
def open(self, options):
|
if self.opened:<EOL><INDENT>return<EOL><DEDENT>self.opened = True<EOL>log.debug('<STR_LIT>', self.id, self.location)<EOL>result = self.download(options)<EOL>log.debug('<STR_LIT>', result)<EOL>return result<EOL>
|
Open and include the refrenced schema.
@param options: An options dictionary.
@type options: L{options.Options}
@return: The referenced schema.
@rtype: L{Schema}
|
f9669:c18:m1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.