partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
test
get_rand_bytes
encoding-->str: one of ENCODINGS l-->int: length of unicode str avoid-->list of int: to void (unprintable chars etc) Returns-->bytes representing unicode str of the requested encoding
cffi_utils/py2to3.py
def get_rand_bytes(encoding='latin1', l=64, avoid=[]): ''' encoding-->str: one of ENCODINGS l-->int: length of unicode str avoid-->list of int: to void (unprintable chars etc) Returns-->bytes representing unicode str of the requested encoding ''' return encode( get_rand_str(encoding=encoding, l=l, avoid=avoid), encoding=encoding )
def get_rand_bytes(encoding='latin1', l=64, avoid=[]): ''' encoding-->str: one of ENCODINGS l-->int: length of unicode str avoid-->list of int: to void (unprintable chars etc) Returns-->bytes representing unicode str of the requested encoding ''' return encode( get_rand_str(encoding=encoding, l=l, avoid=avoid), encoding=encoding )
[ "encoding", "--", ">", "str", ":", "one", "of", "ENCODINGS", "l", "--", ">", "int", ":", "length", "of", "unicode", "str", "avoid", "--", ">", "list", "of", "int", ":", "to", "void", "(", "unprintable", "chars", "etc", ")", "Returns", "--", ">", "bytes", "representing", "unicode", "str", "of", "the", "requested", "encoding" ]
sundarnagarajan/cffi_utils
python
https://github.com/sundarnagarajan/cffi_utils/blob/1d5ab2d2fcb962372228033106bc23f1d73d31fa/cffi_utils/py2to3.py#L353-L363
[ "def", "get_rand_bytes", "(", "encoding", "=", "'latin1'", ",", "l", "=", "64", ",", "avoid", "=", "[", "]", ")", ":", "return", "encode", "(", "get_rand_str", "(", "encoding", "=", "encoding", ",", "l", "=", "l", ",", "avoid", "=", "avoid", ")", ",", "encoding", "=", "encoding", ")" ]
1d5ab2d2fcb962372228033106bc23f1d73d31fa
test
main
Parse argv for options and arguments, and start schema generation.
examples/gen_rt_integrity_check.py
def main(): ''' Parse argv for options and arguments, and start schema generation. ''' parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path...]", formatter=optparse.TitledHelpFormatter()) parser.set_description(__doc__.strip()) parser.add_option("-f", "--function", dest="function", metavar="NAME", help="append integrity checking actions to functions named NAME (required)", action="store", default=None) parser.add_option("-o", "--output", dest='output', metavar="PATH", help="save sql model instances to PATH (required)", action="store", default=None) parser.add_option("-v", "--verbosity", dest='verbosity', action="count", help="increase debug logging level", default=2) (opts, args) = parser.parse_args() if len(args) == 0 or None in [opts.output, opts.function]: parser.print_help() sys.exit(1) levels = { 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG, } logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG)) m = ooaofooa.load_metamodel(args) for c_c in m.select_many('C_C'): filt = lambda sel: ooaofooa.is_contained_in(sel, c_c) and sel.Name == opts.function s_sync = m.select_any('S_SYNC', filt) if not s_sync: s_sync = m.new('S_SYNC', Name=opts.function) pe_pe = m.new('PE_PE') s_dt = m.select_any('S_DT', where(Name='boolean')) relate(pe_pe, s_sync, 8001) relate(s_dt, s_sync, 25) generate_actions(m, c_c, s_sync) xtuml.persist_instances(m, opts.output)
def main(): ''' Parse argv for options and arguments, and start schema generation. ''' parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path...]", formatter=optparse.TitledHelpFormatter()) parser.set_description(__doc__.strip()) parser.add_option("-f", "--function", dest="function", metavar="NAME", help="append integrity checking actions to functions named NAME (required)", action="store", default=None) parser.add_option("-o", "--output", dest='output', metavar="PATH", help="save sql model instances to PATH (required)", action="store", default=None) parser.add_option("-v", "--verbosity", dest='verbosity', action="count", help="increase debug logging level", default=2) (opts, args) = parser.parse_args() if len(args) == 0 or None in [opts.output, opts.function]: parser.print_help() sys.exit(1) levels = { 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG, } logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG)) m = ooaofooa.load_metamodel(args) for c_c in m.select_many('C_C'): filt = lambda sel: ooaofooa.is_contained_in(sel, c_c) and sel.Name == opts.function s_sync = m.select_any('S_SYNC', filt) if not s_sync: s_sync = m.new('S_SYNC', Name=opts.function) pe_pe = m.new('PE_PE') s_dt = m.select_any('S_DT', where(Name='boolean')) relate(pe_pe, s_sync, 8001) relate(s_dt, s_sync, 25) generate_actions(m, c_c, s_sync) xtuml.persist_instances(m, opts.output)
[ "Parse", "argv", "for", "options", "and", "arguments", "and", "start", "schema", "generation", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/examples/gen_rt_integrity_check.py#L253-L302
[ "def", "main", "(", ")", ":", "parser", "=", "optparse", ".", "OptionParser", "(", "usage", "=", "\"%prog [options] <model_path> [another_model_path...]\"", ",", "formatter", "=", "optparse", ".", "TitledHelpFormatter", "(", ")", ")", "parser", ".", "set_description", "(", "__doc__", ".", "strip", "(", ")", ")", "parser", ".", "add_option", "(", "\"-f\"", ",", "\"--function\"", ",", "dest", "=", "\"function\"", ",", "metavar", "=", "\"NAME\"", ",", "help", "=", "\"append integrity checking actions to functions named NAME (required)\"", ",", "action", "=", "\"store\"", ",", "default", "=", "None", ")", "parser", ".", "add_option", "(", "\"-o\"", ",", "\"--output\"", ",", "dest", "=", "'output'", ",", "metavar", "=", "\"PATH\"", ",", "help", "=", "\"save sql model instances to PATH (required)\"", ",", "action", "=", "\"store\"", ",", "default", "=", "None", ")", "parser", ".", "add_option", "(", "\"-v\"", ",", "\"--verbosity\"", ",", "dest", "=", "'verbosity'", ",", "action", "=", "\"count\"", ",", "help", "=", "\"increase debug logging level\"", ",", "default", "=", "2", ")", "(", "opts", ",", "args", ")", "=", "parser", ".", "parse_args", "(", ")", "if", "len", "(", "args", ")", "==", "0", "or", "None", "in", "[", "opts", ".", "output", ",", "opts", ".", "function", "]", ":", "parser", ".", "print_help", "(", ")", "sys", ".", "exit", "(", "1", ")", "levels", "=", "{", "0", ":", "logging", ".", "ERROR", ",", "1", ":", "logging", ".", "WARNING", ",", "2", ":", "logging", ".", "INFO", ",", "3", ":", "logging", ".", "DEBUG", ",", "}", "logging", ".", "basicConfig", "(", "level", "=", "levels", ".", "get", "(", "opts", ".", "verbosity", ",", "logging", ".", "DEBUG", ")", ")", "m", "=", "ooaofooa", ".", "load_metamodel", "(", "args", ")", "for", "c_c", "in", "m", ".", "select_many", "(", "'C_C'", ")", ":", "filt", "=", "lambda", "sel", ":", "ooaofooa", ".", "is_contained_in", "(", "sel", ",", "c_c", ")", "and", "sel", ".", "Name", "==", "opts", ".", "function", "s_sync", "=", "m", ".", "select_any", "(", "'S_SYNC'", ",", "filt", ")", "if", "not", "s_sync", ":", "s_sync", "=", "m", ".", "new", "(", "'S_SYNC'", ",", "Name", "=", "opts", ".", "function", ")", "pe_pe", "=", "m", ".", "new", "(", "'PE_PE'", ")", "s_dt", "=", "m", ".", "select_any", "(", "'S_DT'", ",", "where", "(", "Name", "=", "'boolean'", ")", ")", "relate", "(", "pe_pe", ",", "s_sync", ",", "8001", ")", "relate", "(", "s_dt", ",", "s_sync", ",", "25", ")", "generate_actions", "(", "m", ",", "c_c", ",", "s_sync", ")", "xtuml", ".", "persist_instances", "(", "m", ",", "opts", ".", "output", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
scrape
Rip the events from a given rss feed, normalize the data and store.
comdev/rss_lib.py
def scrape(ctx, url): """ Rip the events from a given rss feed, normalize the data and store. """ data = load_feed(url) feed = data['feed'] entries = data['entries'] # THIS IS SPECIFIC TO # http://konfery.cz/rss/ _type = 'community' country = 'Czech Republic' # title, title_detail, links, link, published, summary, tags # unused: summary_detail, guidislink, published_parsed for entry in entries: _id = sluggify(entry['id']) city = entry['tags'][0]['term'] landing = entry['link'] start_time = dt_normalize(entry['published_parsed'], local_tz=True) title = entry['title'] summary = entry['summary'] link = entry['link'] ipdb.set_trace()
def scrape(ctx, url): """ Rip the events from a given rss feed, normalize the data and store. """ data = load_feed(url) feed = data['feed'] entries = data['entries'] # THIS IS SPECIFIC TO # http://konfery.cz/rss/ _type = 'community' country = 'Czech Republic' # title, title_detail, links, link, published, summary, tags # unused: summary_detail, guidislink, published_parsed for entry in entries: _id = sluggify(entry['id']) city = entry['tags'][0]['term'] landing = entry['link'] start_time = dt_normalize(entry['published_parsed'], local_tz=True) title = entry['title'] summary = entry['summary'] link = entry['link'] ipdb.set_trace()
[ "Rip", "the", "events", "from", "a", "given", "rss", "feed", "normalize", "the", "data", "and", "store", "." ]
kejbaly2/comdev
python
https://github.com/kejbaly2/comdev/blob/5a9067d3c1ae46eeccb9d36e8c231ea5224b42b4/comdev/rss_lib.py#L37-L61
[ "def", "scrape", "(", "ctx", ",", "url", ")", ":", "data", "=", "load_feed", "(", "url", ")", "feed", "=", "data", "[", "'feed'", "]", "entries", "=", "data", "[", "'entries'", "]", "# THIS IS SPECIFIC TO # http://konfery.cz/rss/", "_type", "=", "'community'", "country", "=", "'Czech Republic'", "# title, title_detail, links, link, published, summary, tags", "# unused: summary_detail, guidislink, published_parsed", "for", "entry", "in", "entries", ":", "_id", "=", "sluggify", "(", "entry", "[", "'id'", "]", ")", "city", "=", "entry", "[", "'tags'", "]", "[", "0", "]", "[", "'term'", "]", "landing", "=", "entry", "[", "'link'", "]", "start_time", "=", "dt_normalize", "(", "entry", "[", "'published_parsed'", "]", ",", "local_tz", "=", "True", ")", "title", "=", "entry", "[", "'title'", "]", "summary", "=", "entry", "[", "'summary'", "]", "link", "=", "entry", "[", "'link'", "]", "ipdb", ".", "set_trace", "(", ")" ]
5a9067d3c1ae46eeccb9d36e8c231ea5224b42b4
test
Camera.download_image
Download the image and return the local path to the image file.
zorg_network_camera/adaptor.py
def download_image(self): """ Download the image and return the local path to the image file. """ split = urlsplit(self.url) filename = split.path.split("/")[-1] # Ensure the directory to store the image cache exists if not os.path.exists(self.cache_directory): os.makedirs(self.cache_directory) filepath = os.path.join(self.cache_directory, filename) data = urllib_request.urlopen(self.url) with open(filepath, "wb") as image: image.write(data.read()) return filepath
def download_image(self): """ Download the image and return the local path to the image file. """ split = urlsplit(self.url) filename = split.path.split("/")[-1] # Ensure the directory to store the image cache exists if not os.path.exists(self.cache_directory): os.makedirs(self.cache_directory) filepath = os.path.join(self.cache_directory, filename) data = urllib_request.urlopen(self.url) with open(filepath, "wb") as image: image.write(data.read()) return filepath
[ "Download", "the", "image", "and", "return", "the", "local", "path", "to", "the", "image", "file", "." ]
zorg/zorg-network-camera
python
https://github.com/zorg/zorg-network-camera/blob/e2d15725e50370e2df0c38be6b039215873e4278/zorg_network_camera/adaptor.py#L22-L40
[ "def", "download_image", "(", "self", ")", ":", "split", "=", "urlsplit", "(", "self", ".", "url", ")", "filename", "=", "split", ".", "path", ".", "split", "(", "\"/\"", ")", "[", "-", "1", "]", "# Ensure the directory to store the image cache exists", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "cache_directory", ")", ":", "os", ".", "makedirs", "(", "self", ".", "cache_directory", ")", "filepath", "=", "os", ".", "path", ".", "join", "(", "self", ".", "cache_directory", ",", "filename", ")", "data", "=", "urllib_request", ".", "urlopen", "(", "self", ".", "url", ")", "with", "open", "(", "filepath", ",", "\"wb\"", ")", "as", "image", ":", "image", ".", "write", "(", "data", ".", "read", "(", ")", ")", "return", "filepath" ]
e2d15725e50370e2df0c38be6b039215873e4278
test
Camera.has_changed
Method to check if an image has changed since it was last downloaded. By making a head request, this check can be done quicker that downloading and processing the whole file.
zorg_network_camera/adaptor.py
def has_changed(self): """ Method to check if an image has changed since it was last downloaded. By making a head request, this check can be done quicker that downloading and processing the whole file. """ request = urllib_request.Request(self.url) request.get_method = lambda: 'HEAD' response = urllib_request.urlopen(request) information = response.info() if 'Last-Modified' in information: last_modified = information['Last-Modified'] # Return False if the image has not been modified if last_modified == self.image_last_modified: return False self.image_last_modified = last_modified # Return True if the image has been modified # or if the image has no last-modified header return True
def has_changed(self): """ Method to check if an image has changed since it was last downloaded. By making a head request, this check can be done quicker that downloading and processing the whole file. """ request = urllib_request.Request(self.url) request.get_method = lambda: 'HEAD' response = urllib_request.urlopen(request) information = response.info() if 'Last-Modified' in information: last_modified = information['Last-Modified'] # Return False if the image has not been modified if last_modified == self.image_last_modified: return False self.image_last_modified = last_modified # Return True if the image has been modified # or if the image has no last-modified header return True
[ "Method", "to", "check", "if", "an", "image", "has", "changed", "since", "it", "was", "last", "downloaded", ".", "By", "making", "a", "head", "request", "this", "check", "can", "be", "done", "quicker", "that", "downloading", "and", "processing", "the", "whole", "file", "." ]
zorg/zorg-network-camera
python
https://github.com/zorg/zorg-network-camera/blob/e2d15725e50370e2df0c38be6b039215873e4278/zorg_network_camera/adaptor.py#L42-L67
[ "def", "has_changed", "(", "self", ")", ":", "request", "=", "urllib_request", ".", "Request", "(", "self", ".", "url", ")", "request", ".", "get_method", "=", "lambda", ":", "'HEAD'", "response", "=", "urllib_request", ".", "urlopen", "(", "request", ")", "information", "=", "response", ".", "info", "(", ")", "if", "'Last-Modified'", "in", "information", ":", "last_modified", "=", "information", "[", "'Last-Modified'", "]", "# Return False if the image has not been modified", "if", "last_modified", "==", "self", ".", "image_last_modified", ":", "return", "False", "self", ".", "image_last_modified", "=", "last_modified", "# Return True if the image has been modified", "# or if the image has no last-modified header", "return", "True" ]
e2d15725e50370e2df0c38be6b039215873e4278
test
api_bikes
Gets stolen bikes within a radius of a given postcode. :param request: The aiohttp request. :return: The bikes stolen with the given range from a postcode.
hyperion/api/bike.py
async def api_bikes(request): """ Gets stolen bikes within a radius of a given postcode. :param request: The aiohttp request. :return: The bikes stolen with the given range from a postcode. """ postcode: Optional[str] = request.match_info.get('postcode', None) try: radius = int(request.match_info.get('radius', 10)) except ValueError: raise web.HTTPBadRequest(text="Invalid Radius") try: postcode = (await get_postcode_random()) if postcode == "random" else postcode bikes = await get_bikes(postcode, radius) except CachingError as e: raise web.HTTPInternalServerError(text=e.status) else: if bikes is None: raise web.HTTPNotFound(text="Post code does not exist.") else: return str_json_response([bike.serialize() for bike in bikes])
async def api_bikes(request): """ Gets stolen bikes within a radius of a given postcode. :param request: The aiohttp request. :return: The bikes stolen with the given range from a postcode. """ postcode: Optional[str] = request.match_info.get('postcode', None) try: radius = int(request.match_info.get('radius', 10)) except ValueError: raise web.HTTPBadRequest(text="Invalid Radius") try: postcode = (await get_postcode_random()) if postcode == "random" else postcode bikes = await get_bikes(postcode, radius) except CachingError as e: raise web.HTTPInternalServerError(text=e.status) else: if bikes is None: raise web.HTTPNotFound(text="Post code does not exist.") else: return str_json_response([bike.serialize() for bike in bikes])
[ "Gets", "stolen", "bikes", "within", "a", "radius", "of", "a", "given", "postcode", ".", ":", "param", "request", ":", "The", "aiohttp", "request", ".", ":", "return", ":", "The", "bikes", "stolen", "with", "the", "given", "range", "from", "a", "postcode", "." ]
arlyon/hyperion
python
https://github.com/arlyon/hyperion/blob/d8de0388ba98b85ce472e0f49ac18fecb14d3343/hyperion/api/bike.py#L10-L32
[ "async", "def", "api_bikes", "(", "request", ")", ":", "postcode", ":", "Optional", "[", "str", "]", "=", "request", ".", "match_info", ".", "get", "(", "'postcode'", ",", "None", ")", "try", ":", "radius", "=", "int", "(", "request", ".", "match_info", ".", "get", "(", "'radius'", ",", "10", ")", ")", "except", "ValueError", ":", "raise", "web", ".", "HTTPBadRequest", "(", "text", "=", "\"Invalid Radius\"", ")", "try", ":", "postcode", "=", "(", "await", "get_postcode_random", "(", ")", ")", "if", "postcode", "==", "\"random\"", "else", "postcode", "bikes", "=", "await", "get_bikes", "(", "postcode", ",", "radius", ")", "except", "CachingError", "as", "e", ":", "raise", "web", ".", "HTTPInternalServerError", "(", "text", "=", "e", ".", "status", ")", "else", ":", "if", "bikes", "is", "None", ":", "raise", "web", ".", "HTTPNotFound", "(", "text", "=", "\"Post code does not exist.\"", ")", "else", ":", "return", "str_json_response", "(", "[", "bike", ".", "serialize", "(", ")", "for", "bike", "in", "bikes", "]", ")" ]
d8de0388ba98b85ce472e0f49ac18fecb14d3343
test
fancy_tag_compiler
Returns a template.Node subclass.
fancy_tag/__init__.py
def fancy_tag_compiler(params, defaults, takes_var_args, takes_var_kwargs, takes_context, name, node_class, parser, token): "Returns a template.Node subclass." bits = token.split_contents()[1:] if takes_context: if 'context' in params[:1]: params = params[1:] else: raise TemplateSyntaxError( "Any tag function decorated with takes_context=True " "must have a first argument of 'context'") # Split args and kwargs args = [] kwargs = {} kwarg_found = False unhandled_params = list(params) handled_params = [] if len(bits) > 1 and bits[-2] == 'as': output_var = bits[-1] if len(set(output_var) - set(ALLOWED_VARIABLE_CHARS)) > 0: raise TemplateSyntaxError("%s got output var name with forbidden chars: '%s'" % (name, output_var)) bits = bits[:-2] else: output_var = None for bit in bits: kwarg_match = kwarg_re.match(bit) if kwarg_match: kw, var = kwarg_match.groups() if kw not in params and not takes_var_kwargs: raise TemplateSyntaxError("%s got unknown keyword argument '%s'" % (name, kw)) elif kw in handled_params: raise TemplateSyntaxError("%s got multiple values for keyword argument '%s'" % (name, kw)) else: kwargs[str(kw)] = var kwarg_found = True handled_params.append(kw) else: if kwarg_found: raise TemplateSyntaxError("%s got non-keyword arg after keyword arg" % name) else: args.append(bit) try: handled_params.append(unhandled_params.pop(0)) except IndexError: if not takes_var_args: raise TemplateSyntaxError("%s got too many arguments" % name) # Consider the last n params handled, where n is the number of defaults. if defaults is not None: unhandled_params = unhandled_params[:-len(defaults)] if len(unhandled_params) == 1: raise TemplateSyntaxError("%s didn't get a value for argument '%s'" % (name, unhandled_params[0])) elif len(unhandled_params) > 1: raise TemplateSyntaxError("%s didn't get values for arguments: %s" % ( name, ', '.join(["'%s'" % p for p in unhandled_params]))) return node_class(args, kwargs, output_var, takes_context)
def fancy_tag_compiler(params, defaults, takes_var_args, takes_var_kwargs, takes_context, name, node_class, parser, token): "Returns a template.Node subclass." bits = token.split_contents()[1:] if takes_context: if 'context' in params[:1]: params = params[1:] else: raise TemplateSyntaxError( "Any tag function decorated with takes_context=True " "must have a first argument of 'context'") # Split args and kwargs args = [] kwargs = {} kwarg_found = False unhandled_params = list(params) handled_params = [] if len(bits) > 1 and bits[-2] == 'as': output_var = bits[-1] if len(set(output_var) - set(ALLOWED_VARIABLE_CHARS)) > 0: raise TemplateSyntaxError("%s got output var name with forbidden chars: '%s'" % (name, output_var)) bits = bits[:-2] else: output_var = None for bit in bits: kwarg_match = kwarg_re.match(bit) if kwarg_match: kw, var = kwarg_match.groups() if kw not in params and not takes_var_kwargs: raise TemplateSyntaxError("%s got unknown keyword argument '%s'" % (name, kw)) elif kw in handled_params: raise TemplateSyntaxError("%s got multiple values for keyword argument '%s'" % (name, kw)) else: kwargs[str(kw)] = var kwarg_found = True handled_params.append(kw) else: if kwarg_found: raise TemplateSyntaxError("%s got non-keyword arg after keyword arg" % name) else: args.append(bit) try: handled_params.append(unhandled_params.pop(0)) except IndexError: if not takes_var_args: raise TemplateSyntaxError("%s got too many arguments" % name) # Consider the last n params handled, where n is the number of defaults. if defaults is not None: unhandled_params = unhandled_params[:-len(defaults)] if len(unhandled_params) == 1: raise TemplateSyntaxError("%s didn't get a value for argument '%s'" % (name, unhandled_params[0])) elif len(unhandled_params) > 1: raise TemplateSyntaxError("%s didn't get values for arguments: %s" % ( name, ', '.join(["'%s'" % p for p in unhandled_params]))) return node_class(args, kwargs, output_var, takes_context)
[ "Returns", "a", "template", ".", "Node", "subclass", "." ]
trapeze/fancy_tag
python
https://github.com/trapeze/fancy_tag/blob/0418a995500dc5ac65cf093cb6c1634e3e628229/fancy_tag/__init__.py#L12-L68
[ "def", "fancy_tag_compiler", "(", "params", ",", "defaults", ",", "takes_var_args", ",", "takes_var_kwargs", ",", "takes_context", ",", "name", ",", "node_class", ",", "parser", ",", "token", ")", ":", "bits", "=", "token", ".", "split_contents", "(", ")", "[", "1", ":", "]", "if", "takes_context", ":", "if", "'context'", "in", "params", "[", ":", "1", "]", ":", "params", "=", "params", "[", "1", ":", "]", "else", ":", "raise", "TemplateSyntaxError", "(", "\"Any tag function decorated with takes_context=True \"", "\"must have a first argument of 'context'\"", ")", "# Split args and kwargs", "args", "=", "[", "]", "kwargs", "=", "{", "}", "kwarg_found", "=", "False", "unhandled_params", "=", "list", "(", "params", ")", "handled_params", "=", "[", "]", "if", "len", "(", "bits", ")", ">", "1", "and", "bits", "[", "-", "2", "]", "==", "'as'", ":", "output_var", "=", "bits", "[", "-", "1", "]", "if", "len", "(", "set", "(", "output_var", ")", "-", "set", "(", "ALLOWED_VARIABLE_CHARS", ")", ")", ">", "0", ":", "raise", "TemplateSyntaxError", "(", "\"%s got output var name with forbidden chars: '%s'\"", "%", "(", "name", ",", "output_var", ")", ")", "bits", "=", "bits", "[", ":", "-", "2", "]", "else", ":", "output_var", "=", "None", "for", "bit", "in", "bits", ":", "kwarg_match", "=", "kwarg_re", ".", "match", "(", "bit", ")", "if", "kwarg_match", ":", "kw", ",", "var", "=", "kwarg_match", ".", "groups", "(", ")", "if", "kw", "not", "in", "params", "and", "not", "takes_var_kwargs", ":", "raise", "TemplateSyntaxError", "(", "\"%s got unknown keyword argument '%s'\"", "%", "(", "name", ",", "kw", ")", ")", "elif", "kw", "in", "handled_params", ":", "raise", "TemplateSyntaxError", "(", "\"%s got multiple values for keyword argument '%s'\"", "%", "(", "name", ",", "kw", ")", ")", "else", ":", "kwargs", "[", "str", "(", "kw", ")", "]", "=", "var", "kwarg_found", "=", "True", "handled_params", ".", "append", "(", "kw", ")", "else", ":", "if", "kwarg_found", ":", "raise", "TemplateSyntaxError", "(", "\"%s got non-keyword arg after keyword arg\"", "%", "name", ")", "else", ":", "args", ".", "append", "(", "bit", ")", "try", ":", "handled_params", ".", "append", "(", "unhandled_params", ".", "pop", "(", "0", ")", ")", "except", "IndexError", ":", "if", "not", "takes_var_args", ":", "raise", "TemplateSyntaxError", "(", "\"%s got too many arguments\"", "%", "name", ")", "# Consider the last n params handled, where n is the number of defaults.", "if", "defaults", "is", "not", "None", ":", "unhandled_params", "=", "unhandled_params", "[", ":", "-", "len", "(", "defaults", ")", "]", "if", "len", "(", "unhandled_params", ")", "==", "1", ":", "raise", "TemplateSyntaxError", "(", "\"%s didn't get a value for argument '%s'\"", "%", "(", "name", ",", "unhandled_params", "[", "0", "]", ")", ")", "elif", "len", "(", "unhandled_params", ")", ">", "1", ":", "raise", "TemplateSyntaxError", "(", "\"%s didn't get values for arguments: %s\"", "%", "(", "name", ",", "', '", ".", "join", "(", "[", "\"'%s'\"", "%", "p", "for", "p", "in", "unhandled_params", "]", ")", ")", ")", "return", "node_class", "(", "args", ",", "kwargs", ",", "output_var", ",", "takes_context", ")" ]
0418a995500dc5ac65cf093cb6c1634e3e628229
test
setup_logging
This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_level: str of the overall logging level for setLevel :param str_format: str of the logging format :param date_format: str of the date format :param log_file_level str of the log level to use on this file :param log_stdout_level str of the log level to use on this file (None means no stdout logging) :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param silence_modules list of str of modules to silence :param log_filter: logging.filter instance to add to handler :return: None
seaborn_logger/logger.py
def setup_logging(log_filename=None, log_level="DEBUG", str_format=None, date_format=None, log_file_level="DEBUG", log_stdout_level=None, log_restart=False, log_history=False, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_level: str of the overall logging level for setLevel :param str_format: str of the logging format :param date_format: str of the date format :param log_file_level str of the log level to use on this file :param log_stdout_level str of the log level to use on this file (None means no stdout logging) :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param silence_modules list of str of modules to silence :param log_filter: logging.filter instance to add to handler :return: None """ setup_log_level(log_level) if log_filename: setup_file_logging(log_filename=log_filename, str_format=str_format, log_history=log_history, formatter=formatter, log_file_level=log_file_level, log_restart=log_restart, date_format=date_format, log_filter=log_filter) if log_stdout_level is not None: setup_stdout_logging(log_level=log_level, log_stdout_level=log_stdout_level, str_format=str_format, date_format=date_format, formatter=formatter, log_filter=log_filter) silence_module_logging(silence_modules)
def setup_logging(log_filename=None, log_level="DEBUG", str_format=None, date_format=None, log_file_level="DEBUG", log_stdout_level=None, log_restart=False, log_history=False, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_level: str of the overall logging level for setLevel :param str_format: str of the logging format :param date_format: str of the date format :param log_file_level str of the log level to use on this file :param log_stdout_level str of the log level to use on this file (None means no stdout logging) :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param silence_modules list of str of modules to silence :param log_filter: logging.filter instance to add to handler :return: None """ setup_log_level(log_level) if log_filename: setup_file_logging(log_filename=log_filename, str_format=str_format, log_history=log_history, formatter=formatter, log_file_level=log_file_level, log_restart=log_restart, date_format=date_format, log_filter=log_filter) if log_stdout_level is not None: setup_stdout_logging(log_level=log_level, log_stdout_level=log_stdout_level, str_format=str_format, date_format=date_format, formatter=formatter, log_filter=log_filter) silence_module_logging(silence_modules)
[ "This", "will", "setup", "logging", "for", "a", "single", "file", "but", "can", "be", "called", "more", "than", "once", "LOG", "LEVELS", "are", "CRITICAL", "ERROR", "INFO", "DEBUG", ":", "param", "log_filename", ":", "str", "of", "the", "file", "location", ":", "param", "log_level", ":", "str", "of", "the", "overall", "logging", "level", "for", "setLevel", ":", "param", "str_format", ":", "str", "of", "the", "logging", "format", ":", "param", "date_format", ":", "str", "of", "the", "date", "format", ":", "param", "log_file_level", "str", "of", "the", "log", "level", "to", "use", "on", "this", "file", ":", "param", "log_stdout_level", "str", "of", "the", "log", "level", "to", "use", "on", "this", "file", "(", "None", "means", "no", "stdout", "logging", ")", ":", "param", "log_restart", ":", "bool", "if", "True", "the", "log", "file", "will", "be", "deleted", "first", ":", "param", "log_history", ":", "bool", "if", "True", "will", "save", "another", "log", "file", "in", "a", "folder", "called", "history", "with", "the", "datetime", ":", "param", "formatter", ":", "logging", ".", "Format", "instance", "to", "use", ":", "param", "silence_modules", "list", "of", "str", "of", "modules", "to", "silence", ":", "param", "log_filter", ":", "logging", ".", "filter", "instance", "to", "add", "to", "handler", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L220-L258
[ "def", "setup_logging", "(", "log_filename", "=", "None", ",", "log_level", "=", "\"DEBUG\"", ",", "str_format", "=", "None", ",", "date_format", "=", "None", ",", "log_file_level", "=", "\"DEBUG\"", ",", "log_stdout_level", "=", "None", ",", "log_restart", "=", "False", ",", "log_history", "=", "False", ",", "formatter", "=", "None", ",", "silence_modules", "=", "None", ",", "log_filter", "=", "None", ")", ":", "setup_log_level", "(", "log_level", ")", "if", "log_filename", ":", "setup_file_logging", "(", "log_filename", "=", "log_filename", ",", "str_format", "=", "str_format", ",", "log_history", "=", "log_history", ",", "formatter", "=", "formatter", ",", "log_file_level", "=", "log_file_level", ",", "log_restart", "=", "log_restart", ",", "date_format", "=", "date_format", ",", "log_filter", "=", "log_filter", ")", "if", "log_stdout_level", "is", "not", "None", ":", "setup_stdout_logging", "(", "log_level", "=", "log_level", ",", "log_stdout_level", "=", "log_stdout_level", ",", "str_format", "=", "str_format", ",", "date_format", "=", "date_format", ",", "formatter", "=", "formatter", ",", "log_filter", "=", "log_filter", ")", "silence_module_logging", "(", "silence_modules", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
setup_stdout_logging
This will setup logging for stdout and stderr :param formatter: :param log_level: str of the overall logging level for setLevel :param log_stdout_level: str of the logging level of stdout :param str_format: str of the logging format :param date_format: str of the date format :param silence_modules: list of str of modules to exclude from logging :param log_filter: logging.filter instance to add to handler :return: None
seaborn_logger/logger.py
def setup_stdout_logging(log_level="DEBUG", log_stdout_level="DEBUG", str_format=None, date_format=None, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for stdout and stderr :param formatter: :param log_level: str of the overall logging level for setLevel :param log_stdout_level: str of the logging level of stdout :param str_format: str of the logging format :param date_format: str of the date format :param silence_modules: list of str of modules to exclude from logging :param log_filter: logging.filter instance to add to handler :return: None """ setup_log_level(log_level) formatter = formatter or SeabornFormatter(str_format, date_format) if log_stdout_level != 'ERROR': stdout_handler = logging.StreamHandler(sys.__stdout__) add_handler(log_stdout_level, stdout_handler, formatter, NoErrorFilter()) stderr_handler = logging.StreamHandler(sys.__stderr__) add_handler("ERROR", stderr_handler, formatter, log_filter) silence_module_logging(silence_modules)
def setup_stdout_logging(log_level="DEBUG", log_stdout_level="DEBUG", str_format=None, date_format=None, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for stdout and stderr :param formatter: :param log_level: str of the overall logging level for setLevel :param log_stdout_level: str of the logging level of stdout :param str_format: str of the logging format :param date_format: str of the date format :param silence_modules: list of str of modules to exclude from logging :param log_filter: logging.filter instance to add to handler :return: None """ setup_log_level(log_level) formatter = formatter or SeabornFormatter(str_format, date_format) if log_stdout_level != 'ERROR': stdout_handler = logging.StreamHandler(sys.__stdout__) add_handler(log_stdout_level, stdout_handler, formatter, NoErrorFilter()) stderr_handler = logging.StreamHandler(sys.__stderr__) add_handler("ERROR", stderr_handler, formatter, log_filter) silence_module_logging(silence_modules)
[ "This", "will", "setup", "logging", "for", "stdout", "and", "stderr", ":", "param", "formatter", ":", ":", "param", "log_level", ":", "str", "of", "the", "overall", "logging", "level", "for", "setLevel", ":", "param", "log_stdout_level", ":", "str", "of", "the", "logging", "level", "of", "stdout", ":", "param", "str_format", ":", "str", "of", "the", "logging", "format", ":", "param", "date_format", ":", "str", "of", "the", "date", "format", ":", "param", "silence_modules", ":", "list", "of", "str", "of", "modules", "to", "exclude", "from", "logging", ":", "param", "log_filter", ":", "logging", ".", "filter", "instance", "to", "add", "to", "handler", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L261-L286
[ "def", "setup_stdout_logging", "(", "log_level", "=", "\"DEBUG\"", ",", "log_stdout_level", "=", "\"DEBUG\"", ",", "str_format", "=", "None", ",", "date_format", "=", "None", ",", "formatter", "=", "None", ",", "silence_modules", "=", "None", ",", "log_filter", "=", "None", ")", ":", "setup_log_level", "(", "log_level", ")", "formatter", "=", "formatter", "or", "SeabornFormatter", "(", "str_format", ",", "date_format", ")", "if", "log_stdout_level", "!=", "'ERROR'", ":", "stdout_handler", "=", "logging", ".", "StreamHandler", "(", "sys", ".", "__stdout__", ")", "add_handler", "(", "log_stdout_level", ",", "stdout_handler", ",", "formatter", ",", "NoErrorFilter", "(", ")", ")", "stderr_handler", "=", "logging", ".", "StreamHandler", "(", "sys", ".", "__stderr__", ")", "add_handler", "(", "\"ERROR\"", ",", "stderr_handler", ",", "formatter", ",", "log_filter", ")", "silence_module_logging", "(", "silence_modules", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
setup_file_logging
This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :param silence_modules list of str of modules to silence :return: None
seaborn_logger/logger.py
def setup_file_logging(log_filename, log_file_level="DEBUG", str_format=None, date_format=None, log_restart=False, log_history=False, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :param silence_modules list of str of modules to silence :return: None """ from seaborn_timestamp.timestamp import datetime_to_str if os.path.exists(log_filename) and log_restart: os.remove(log_filename) add_file_handler(log_file_level, log_filename, str_format=str_format, date_format=date_format, formatter=formatter, log_filter=log_filter) if log_history: base_name = os.path.basename(log_filename).split('.')[0] + \ '_%s' % datetime_to_str(str_format='%Y-%m-%d_%H-%M-%S') history_log = os.path.join(os.path.dirname(log_filename), 'history', base_name + '.log') add_file_handler(log_file_level, history_log, str_format=str_format, date_format=date_format, log_filter=log_filter) silence_module_logging(silence_modules)
def setup_file_logging(log_filename, log_file_level="DEBUG", str_format=None, date_format=None, log_restart=False, log_history=False, formatter=None, silence_modules=None, log_filter=None): """ This will setup logging for a single file but can be called more than once LOG LEVELS are "CRITICAL", "ERROR", "INFO", "DEBUG" :param log_filename: str of the file location :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :param silence_modules list of str of modules to silence :return: None """ from seaborn_timestamp.timestamp import datetime_to_str if os.path.exists(log_filename) and log_restart: os.remove(log_filename) add_file_handler(log_file_level, log_filename, str_format=str_format, date_format=date_format, formatter=formatter, log_filter=log_filter) if log_history: base_name = os.path.basename(log_filename).split('.')[0] + \ '_%s' % datetime_to_str(str_format='%Y-%m-%d_%H-%M-%S') history_log = os.path.join(os.path.dirname(log_filename), 'history', base_name + '.log') add_file_handler(log_file_level, history_log, str_format=str_format, date_format=date_format, log_filter=log_filter) silence_module_logging(silence_modules)
[ "This", "will", "setup", "logging", "for", "a", "single", "file", "but", "can", "be", "called", "more", "than", "once", "LOG", "LEVELS", "are", "CRITICAL", "ERROR", "INFO", "DEBUG", ":", "param", "log_filename", ":", "str", "of", "the", "file", "location", ":", "param", "log_file_level", "str", "of", "the", "log", "level", "to", "use", "on", "this", "file", ":", "param", "str_format", ":", "str", "of", "the", "logging", "format", ":", "param", "date_format", ":", "str", "of", "the", "date", "format", ":", "param", "log_restart", ":", "bool", "if", "True", "the", "log", "file", "will", "be", "deleted", "first", ":", "param", "log_history", ":", "bool", "if", "True", "will", "save", "another", "log", "file", "in", "a", "folder", "called", "history", "with", "the", "datetime", ":", "param", "formatter", ":", "logging", ".", "Format", "instance", "to", "use", ":", "param", "log_filter", ":", "logging", ".", "filter", "instance", "to", "add", "to", "handler", ":", "param", "silence_modules", "list", "of", "str", "of", "modules", "to", "silence", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L289-L323
[ "def", "setup_file_logging", "(", "log_filename", ",", "log_file_level", "=", "\"DEBUG\"", ",", "str_format", "=", "None", ",", "date_format", "=", "None", ",", "log_restart", "=", "False", ",", "log_history", "=", "False", ",", "formatter", "=", "None", ",", "silence_modules", "=", "None", ",", "log_filter", "=", "None", ")", ":", "from", "seaborn_timestamp", ".", "timestamp", "import", "datetime_to_str", "if", "os", ".", "path", ".", "exists", "(", "log_filename", ")", "and", "log_restart", ":", "os", ".", "remove", "(", "log_filename", ")", "add_file_handler", "(", "log_file_level", ",", "log_filename", ",", "str_format", "=", "str_format", ",", "date_format", "=", "date_format", ",", "formatter", "=", "formatter", ",", "log_filter", "=", "log_filter", ")", "if", "log_history", ":", "base_name", "=", "os", ".", "path", ".", "basename", "(", "log_filename", ")", ".", "split", "(", "'.'", ")", "[", "0", "]", "+", "'_%s'", "%", "datetime_to_str", "(", "str_format", "=", "'%Y-%m-%d_%H-%M-%S'", ")", "history_log", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "log_filename", ")", ",", "'history'", ",", "base_name", "+", "'.log'", ")", "add_file_handler", "(", "log_file_level", ",", "history_log", ",", "str_format", "=", "str_format", ",", "date_format", "=", "date_format", ",", "log_filter", "=", "log_filter", ")", "silence_module_logging", "(", "silence_modules", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
add_file_handler
:param log_filename: :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :return: None
seaborn_logger/logger.py
def add_file_handler(log_file_level, log_filename, str_format=None, date_format=None, formatter=None, log_filter=None): """ :param log_filename: :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :return: None """ formatter = formatter or SeabornFormatter(str_format=str_format, date_format=date_format) mkdir_for_file(log_filename) handler = logging.FileHandler(log_filename) add_handler(log_file_level, handler, formatter, log_filter=log_filter)
def add_file_handler(log_file_level, log_filename, str_format=None, date_format=None, formatter=None, log_filter=None): """ :param log_filename: :param log_file_level str of the log level to use on this file :param str_format: str of the logging format :param date_format: str of the date format :param log_restart: bool if True the log file will be deleted first :param log_history: bool if True will save another log file in a folder called history with the datetime :param formatter: logging.Format instance to use :param log_filter: logging.filter instance to add to handler :return: None """ formatter = formatter or SeabornFormatter(str_format=str_format, date_format=date_format) mkdir_for_file(log_filename) handler = logging.FileHandler(log_filename) add_handler(log_file_level, handler, formatter, log_filter=log_filter)
[ ":", "param", "log_filename", ":", ":", "param", "log_file_level", "str", "of", "the", "log", "level", "to", "use", "on", "this", "file", ":", "param", "str_format", ":", "str", "of", "the", "logging", "format", ":", "param", "date_format", ":", "str", "of", "the", "date", "format", ":", "param", "log_restart", ":", "bool", "if", "True", "the", "log", "file", "will", "be", "deleted", "first", ":", "param", "log_history", ":", "bool", "if", "True", "will", "save", "another", "log", "file", "in", "a", "folder", "called", "history", "with", "the", "datetime", ":", "param", "formatter", ":", "logging", ".", "Format", "instance", "to", "use", ":", "param", "log_filter", ":", "logging", ".", "filter", "instance", "to", "add", "to", "handler", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L326-L345
[ "def", "add_file_handler", "(", "log_file_level", ",", "log_filename", ",", "str_format", "=", "None", ",", "date_format", "=", "None", ",", "formatter", "=", "None", ",", "log_filter", "=", "None", ")", ":", "formatter", "=", "formatter", "or", "SeabornFormatter", "(", "str_format", "=", "str_format", ",", "date_format", "=", "date_format", ")", "mkdir_for_file", "(", "log_filename", ")", "handler", "=", "logging", ".", "FileHandler", "(", "log_filename", ")", "add_handler", "(", "log_file_level", ",", "handler", ",", "formatter", ",", "log_filter", "=", "log_filter", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
add_handler
:param log_handler_level: str of the level to set for the handler :param handler: logging.Handler handler to add :param formatter: logging.Formatter instance to use :param log_filter: logging.filter instance to add to handler :return: None
seaborn_logger/logger.py
def add_handler(log_handler_level, handler, formatter=None, log_filter=None): """ :param log_handler_level: str of the level to set for the handler :param handler: logging.Handler handler to add :param formatter: logging.Formatter instance to use :param log_filter: logging.filter instance to add to handler :return: None """ handler.setLevel(log_handler_level) if formatter is not None: handler.setFormatter(formatter) if log_filter is not None: handler.addFilter(log_filter) log.addHandler(handler)
def add_handler(log_handler_level, handler, formatter=None, log_filter=None): """ :param log_handler_level: str of the level to set for the handler :param handler: logging.Handler handler to add :param formatter: logging.Formatter instance to use :param log_filter: logging.filter instance to add to handler :return: None """ handler.setLevel(log_handler_level) if formatter is not None: handler.setFormatter(formatter) if log_filter is not None: handler.addFilter(log_filter) log.addHandler(handler)
[ ":", "param", "log_handler_level", ":", "str", "of", "the", "level", "to", "set", "for", "the", "handler", ":", "param", "handler", ":", "logging", ".", "Handler", "handler", "to", "add", ":", "param", "formatter", ":", "logging", ".", "Formatter", "instance", "to", "use", ":", "param", "log_filter", ":", "logging", ".", "filter", "instance", "to", "add", "to", "handler", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L348-L361
[ "def", "add_handler", "(", "log_handler_level", ",", "handler", ",", "formatter", "=", "None", ",", "log_filter", "=", "None", ")", ":", "handler", ".", "setLevel", "(", "log_handler_level", ")", "if", "formatter", "is", "not", "None", ":", "handler", ".", "setFormatter", "(", "formatter", ")", "if", "log_filter", "is", "not", "None", ":", "handler", ".", "addFilter", "(", "log_filter", ")", "log", ".", "addHandler", "(", "handler", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
set_module_log_level
This will raise the log level for the given modules in general this is used to silence them :param modules: list of str of module names ex. ['requests'] :param log_level: str of the new log level :return: None
seaborn_logger/logger.py
def set_module_log_level(modules=None, log_level=logging.WARNING): """ This will raise the log level for the given modules in general this is used to silence them :param modules: list of str of module names ex. ['requests'] :param log_level: str of the new log level :return: None """ modules = modules or [] if not isinstance(modules, list): modules = [modules] for module in modules: logging.getLogger(module).setLevel(logging.WARNING)
def set_module_log_level(modules=None, log_level=logging.WARNING): """ This will raise the log level for the given modules in general this is used to silence them :param modules: list of str of module names ex. ['requests'] :param log_level: str of the new log level :return: None """ modules = modules or [] if not isinstance(modules, list): modules = [modules] for module in modules: logging.getLogger(module).setLevel(logging.WARNING)
[ "This", "will", "raise", "the", "log", "level", "for", "the", "given", "modules", "in", "general", "this", "is", "used", "to", "silence", "them", ":", "param", "modules", ":", "list", "of", "str", "of", "module", "names", "ex", ".", "[", "requests", "]", ":", "param", "log_level", ":", "str", "of", "the", "new", "log", "level", ":", "return", ":", "None" ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L364-L376
[ "def", "set_module_log_level", "(", "modules", "=", "None", ",", "log_level", "=", "logging", ".", "WARNING", ")", ":", "modules", "=", "modules", "or", "[", "]", "if", "not", "isinstance", "(", "modules", ",", "list", ")", ":", "modules", "=", "[", "modules", "]", "for", "module", "in", "modules", ":", "logging", ".", "getLogger", "(", "module", ")", ".", "setLevel", "(", "logging", ".", "WARNING", ")" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
SeabornLogger.findCaller
Find the stack frame of the caller so that we can note the source file name, line number and function name.
seaborn_logger/logger.py
def findCaller(self, stack_info=False): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ f = logging.currentframe() # On some versions of IronPython, currentframe() returns None if # IronPython isn't run with -X:Frames. if f is not None: f = f.f_back rv = "(unknown file)", 0, "(unknown function)" while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename == logging._srcfile or filename == self._srcfile: f = f.f_back continue rv = (co.co_filename, f.f_lineno, co.co_name) if stack_info: sio = io.StringIO() sio.write('Stack (most recent call last):\n') traceback.print_stack(f, file=sio) sinfo = sio.getvalue() if sinfo[-1] == '\n': sinfo = sinfo[:-1] sio.close() break return rv
def findCaller(self, stack_info=False): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ f = logging.currentframe() # On some versions of IronPython, currentframe() returns None if # IronPython isn't run with -X:Frames. if f is not None: f = f.f_back rv = "(unknown file)", 0, "(unknown function)" while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename == logging._srcfile or filename == self._srcfile: f = f.f_back continue rv = (co.co_filename, f.f_lineno, co.co_name) if stack_info: sio = io.StringIO() sio.write('Stack (most recent call last):\n') traceback.print_stack(f, file=sio) sinfo = sio.getvalue() if sinfo[-1] == '\n': sinfo = sinfo[:-1] sio.close() break return rv
[ "Find", "the", "stack", "frame", "of", "the", "caller", "so", "that", "we", "can", "note", "the", "source", "file", "name", "line", "number", "and", "function", "name", "." ]
SeabornGames/Logger
python
https://github.com/SeabornGames/Logger/blob/fb8b1700557aaea8d3216bd4c4df33c302bece7f/seaborn_logger/logger.py#L45-L72
[ "def", "findCaller", "(", "self", ",", "stack_info", "=", "False", ")", ":", "f", "=", "logging", ".", "currentframe", "(", ")", "# On some versions of IronPython, currentframe() returns None if", "# IronPython isn't run with -X:Frames.", "if", "f", "is", "not", "None", ":", "f", "=", "f", ".", "f_back", "rv", "=", "\"(unknown file)\"", ",", "0", ",", "\"(unknown function)\"", "while", "hasattr", "(", "f", ",", "\"f_code\"", ")", ":", "co", "=", "f", ".", "f_code", "filename", "=", "os", ".", "path", ".", "normcase", "(", "co", ".", "co_filename", ")", "if", "filename", "==", "logging", ".", "_srcfile", "or", "filename", "==", "self", ".", "_srcfile", ":", "f", "=", "f", ".", "f_back", "continue", "rv", "=", "(", "co", ".", "co_filename", ",", "f", ".", "f_lineno", ",", "co", ".", "co_name", ")", "if", "stack_info", ":", "sio", "=", "io", ".", "StringIO", "(", ")", "sio", ".", "write", "(", "'Stack (most recent call last):\\n'", ")", "traceback", ".", "print_stack", "(", "f", ",", "file", "=", "sio", ")", "sinfo", "=", "sio", ".", "getvalue", "(", ")", "if", "sinfo", "[", "-", "1", "]", "==", "'\\n'", ":", "sinfo", "=", "sinfo", "[", ":", "-", "1", "]", "sio", ".", "close", "(", ")", "break", "return", "rv" ]
fb8b1700557aaea8d3216bd4c4df33c302bece7f
test
get_defining_component
get the C_C in which pe_pe is defined
bridgepoint/prebuild.py
def get_defining_component(pe_pe): ''' get the C_C in which pe_pe is defined ''' if pe_pe is None: return None if pe_pe.__class__.__name__ != 'PE_PE': pe_pe = xtuml.navigate_one(pe_pe).PE_PE[8001]() ep_pkg = xtuml.navigate_one(pe_pe).EP_PKG[8000]() if ep_pkg: return get_defining_component(ep_pkg) return xtuml.navigate_one(pe_pe).C_C[8003]()
def get_defining_component(pe_pe): ''' get the C_C in which pe_pe is defined ''' if pe_pe is None: return None if pe_pe.__class__.__name__ != 'PE_PE': pe_pe = xtuml.navigate_one(pe_pe).PE_PE[8001]() ep_pkg = xtuml.navigate_one(pe_pe).EP_PKG[8000]() if ep_pkg: return get_defining_component(ep_pkg) return xtuml.navigate_one(pe_pe).C_C[8003]()
[ "get", "the", "C_C", "in", "which", "pe_pe", "is", "defined" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/prebuild.py#L46-L61
[ "def", "get_defining_component", "(", "pe_pe", ")", ":", "if", "pe_pe", "is", "None", ":", "return", "None", "if", "pe_pe", ".", "__class__", ".", "__name__", "!=", "'PE_PE'", ":", "pe_pe", "=", "xtuml", ".", "navigate_one", "(", "pe_pe", ")", ".", "PE_PE", "[", "8001", "]", "(", ")", "ep_pkg", "=", "xtuml", ".", "navigate_one", "(", "pe_pe", ")", ".", "EP_PKG", "[", "8000", "]", "(", ")", "if", "ep_pkg", ":", "return", "get_defining_component", "(", "ep_pkg", ")", "return", "xtuml", ".", "navigate_one", "(", "pe_pe", ")", ".", "C_C", "[", "8003", "]", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
prebuild_action
Transform textual OAL actions of an *instance* to instances in the ooaofooa subsystems Value and Body. The provided *instance* must be an instance of one of the following classes: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS
bridgepoint/prebuild.py
def prebuild_action(instance): ''' Transform textual OAL actions of an *instance* to instances in the ooaofooa subsystems Value and Body. The provided *instance* must be an instance of one of the following classes: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS ''' walker_map = { 'S_SYNC': FunctionPrebuilder, 'S_BRG': BridgePrebuilder, 'O_TFR': OperationPrebuilder, 'O_DBATTR': DerivedAttributePrebuilder, 'SM_ACT': TransitionPrebuilder, 'SPR_RO': RequiredOperationPrebuilder, 'SPR_RS': RequiredSignalPrebuilder, 'SPR_PO': ProvidedOperationPrebuilder, 'SPR_PS': ProvidedSignalPrebuilder } metaclass = xtuml.get_metaclass(instance) walker = walker_map[metaclass.kind](metaclass.metamodel, instance) logger.info('processing action %s' % walker.label) # walker.visitors.append(xtuml.tools.NodePrintVisitor()) root = oal.parse(instance.Action_Semantics_internal) return walker.accept(root)
def prebuild_action(instance): ''' Transform textual OAL actions of an *instance* to instances in the ooaofooa subsystems Value and Body. The provided *instance* must be an instance of one of the following classes: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS ''' walker_map = { 'S_SYNC': FunctionPrebuilder, 'S_BRG': BridgePrebuilder, 'O_TFR': OperationPrebuilder, 'O_DBATTR': DerivedAttributePrebuilder, 'SM_ACT': TransitionPrebuilder, 'SPR_RO': RequiredOperationPrebuilder, 'SPR_RS': RequiredSignalPrebuilder, 'SPR_PO': ProvidedOperationPrebuilder, 'SPR_PS': ProvidedSignalPrebuilder } metaclass = xtuml.get_metaclass(instance) walker = walker_map[metaclass.kind](metaclass.metamodel, instance) logger.info('processing action %s' % walker.label) # walker.visitors.append(xtuml.tools.NodePrintVisitor()) root = oal.parse(instance.Action_Semantics_internal) return walker.accept(root)
[ "Transform", "textual", "OAL", "actions", "of", "an", "*", "instance", "*", "to", "instances", "in", "the", "ooaofooa", "subsystems", "Value", "and", "Body", ".", "The", "provided", "*", "instance", "*", "must", "be", "an", "instance", "of", "one", "of", "the", "following", "classes", ":", "-", "S_SYNC", "-", "S_BRG", "-", "O_TFR", "-", "O_DBATTR", "-", "SM_ACT", "-", "SPR_RO", "-", "SPR_RS", "-", "SPR_PO", "-", "SPR_PS" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/prebuild.py#L1796-L1828
[ "def", "prebuild_action", "(", "instance", ")", ":", "walker_map", "=", "{", "'S_SYNC'", ":", "FunctionPrebuilder", ",", "'S_BRG'", ":", "BridgePrebuilder", ",", "'O_TFR'", ":", "OperationPrebuilder", ",", "'O_DBATTR'", ":", "DerivedAttributePrebuilder", ",", "'SM_ACT'", ":", "TransitionPrebuilder", ",", "'SPR_RO'", ":", "RequiredOperationPrebuilder", ",", "'SPR_RS'", ":", "RequiredSignalPrebuilder", ",", "'SPR_PO'", ":", "ProvidedOperationPrebuilder", ",", "'SPR_PS'", ":", "ProvidedSignalPrebuilder", "}", "metaclass", "=", "xtuml", ".", "get_metaclass", "(", "instance", ")", "walker", "=", "walker_map", "[", "metaclass", ".", "kind", "]", "(", "metaclass", ".", "metamodel", ",", "instance", ")", "logger", ".", "info", "(", "'processing action %s'", "%", "walker", ".", "label", ")", "# walker.visitors.append(xtuml.tools.NodePrintVisitor())", "root", "=", "oal", ".", "parse", "(", "instance", ".", "Action_Semantics_internal", ")", "return", "walker", ".", "accept", "(", "root", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
prebuild_model
Transform textual OAL actions in a ooaofooa *metamodel* to instances in the subsystems Value and Body. Instances of the following classes are supported: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS
bridgepoint/prebuild.py
def prebuild_model(metamodel): ''' Transform textual OAL actions in a ooaofooa *metamodel* to instances in the subsystems Value and Body. Instances of the following classes are supported: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS ''' for kind in ['S_SYNC','S_BRG','O_TFR', 'O_DBATTR', 'SM_ACT', 'SPR_RO', 'SPR_RS', 'SPR_PO', 'SPR_PS']: for inst in metamodel.select_many(kind): if inst.Suc_Pars: prebuild_action(inst)
def prebuild_model(metamodel): ''' Transform textual OAL actions in a ooaofooa *metamodel* to instances in the subsystems Value and Body. Instances of the following classes are supported: - S_SYNC - S_BRG - O_TFR - O_DBATTR - SM_ACT - SPR_RO - SPR_RS - SPR_PO - SPR_PS ''' for kind in ['S_SYNC','S_BRG','O_TFR', 'O_DBATTR', 'SM_ACT', 'SPR_RO', 'SPR_RS', 'SPR_PO', 'SPR_PS']: for inst in metamodel.select_many(kind): if inst.Suc_Pars: prebuild_action(inst)
[ "Transform", "textual", "OAL", "actions", "in", "a", "ooaofooa", "*", "metamodel", "*", "to", "instances", "in", "the", "subsystems", "Value", "and", "Body", ".", "Instances", "of", "the", "following", "classes", "are", "supported", ":", "-", "S_SYNC", "-", "S_BRG", "-", "O_TFR", "-", "O_DBATTR", "-", "SM_ACT", "-", "SPR_RO", "-", "SPR_RS", "-", "SPR_PO", "-", "SPR_PS" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/prebuild.py#L1831-L1850
[ "def", "prebuild_model", "(", "metamodel", ")", ":", "for", "kind", "in", "[", "'S_SYNC'", ",", "'S_BRG'", ",", "'O_TFR'", ",", "'O_DBATTR'", ",", "'SM_ACT'", ",", "'SPR_RO'", ",", "'SPR_RS'", ",", "'SPR_PO'", ",", "'SPR_PS'", "]", ":", "for", "inst", "in", "metamodel", ".", "select_many", "(", "kind", ")", ":", "if", "inst", ".", "Suc_Pars", ":", "prebuild_action", "(", "inst", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
main
Parse command line options and launch the prebuilder.
bridgepoint/prebuild.py
def main(): ''' Parse command line options and launch the prebuilder. ''' parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path..]", version=xtuml.version.complete_string, formatter=optparse.TitledHelpFormatter()) parser.add_option("-v", "--verbosity", dest='verbosity', action="count", help="increase debug logging level", default=1) parser.add_option("-o", "--output", dest="output", metavar="PATH", help="set output to PATH", action="store", default=None) (opts, args) = parser.parse_args() if len(args) == 0 or opts.output is None: parser.print_help() sys.exit(1) levels = { 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG, } logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG)) m = ooaofooa.load_metamodel(args) prebuild_model(m) xtuml.persist_instances(m, opts.output)
def main(): ''' Parse command line options and launch the prebuilder. ''' parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path..]", version=xtuml.version.complete_string, formatter=optparse.TitledHelpFormatter()) parser.add_option("-v", "--verbosity", dest='verbosity', action="count", help="increase debug logging level", default=1) parser.add_option("-o", "--output", dest="output", metavar="PATH", help="set output to PATH", action="store", default=None) (opts, args) = parser.parse_args() if len(args) == 0 or opts.output is None: parser.print_help() sys.exit(1) levels = { 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG, } logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG)) m = ooaofooa.load_metamodel(args) prebuild_model(m) xtuml.persist_instances(m, opts.output)
[ "Parse", "command", "line", "options", "and", "launch", "the", "prebuilder", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/prebuild.py#L1853-L1887
[ "def", "main", "(", ")", ":", "parser", "=", "optparse", ".", "OptionParser", "(", "usage", "=", "\"%prog [options] <model_path> [another_model_path..]\"", ",", "version", "=", "xtuml", ".", "version", ".", "complete_string", ",", "formatter", "=", "optparse", ".", "TitledHelpFormatter", "(", ")", ")", "parser", ".", "add_option", "(", "\"-v\"", ",", "\"--verbosity\"", ",", "dest", "=", "'verbosity'", ",", "action", "=", "\"count\"", ",", "help", "=", "\"increase debug logging level\"", ",", "default", "=", "1", ")", "parser", ".", "add_option", "(", "\"-o\"", ",", "\"--output\"", ",", "dest", "=", "\"output\"", ",", "metavar", "=", "\"PATH\"", ",", "help", "=", "\"set output to PATH\"", ",", "action", "=", "\"store\"", ",", "default", "=", "None", ")", "(", "opts", ",", "args", ")", "=", "parser", ".", "parse_args", "(", ")", "if", "len", "(", "args", ")", "==", "0", "or", "opts", ".", "output", "is", "None", ":", "parser", ".", "print_help", "(", ")", "sys", ".", "exit", "(", "1", ")", "levels", "=", "{", "0", ":", "logging", ".", "ERROR", ",", "1", ":", "logging", ".", "WARNING", ",", "2", ":", "logging", ".", "INFO", ",", "3", ":", "logging", ".", "DEBUG", ",", "}", "logging", ".", "basicConfig", "(", "level", "=", "levels", ".", "get", "(", "opts", ".", "verbosity", ",", "logging", ".", "DEBUG", ")", ")", "m", "=", "ooaofooa", ".", "load_metamodel", "(", "args", ")", "prebuild_model", "(", "m", ")", "xtuml", ".", "persist_instances", "(", "m", ",", "opts", ".", "output", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
SymbolTable.find_symbol
Find a symbol in the symbol table by name, kind, or both.
bridgepoint/prebuild.py
def find_symbol(self, name=None, kind=None): ''' Find a symbol in the symbol table by name, kind, or both. ''' for s in reversed(self.stack): for symbol_name, handle in s.symbols.items(): symbol_kind = handle.__class__.__name__ if name == symbol_name and kind == symbol_kind: return handle elif name is None and kind == handle.__class__.__name__: return handle elif name == symbol_name and kind is None: return handle if name is None and kind == s.handle.__class__.__name__: return s.handle
def find_symbol(self, name=None, kind=None): ''' Find a symbol in the symbol table by name, kind, or both. ''' for s in reversed(self.stack): for symbol_name, handle in s.symbols.items(): symbol_kind = handle.__class__.__name__ if name == symbol_name and kind == symbol_kind: return handle elif name is None and kind == handle.__class__.__name__: return handle elif name == symbol_name and kind is None: return handle if name is None and kind == s.handle.__class__.__name__: return s.handle
[ "Find", "a", "symbol", "in", "the", "symbol", "table", "by", "name", "kind", "or", "both", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/prebuild.py#L90-L109
[ "def", "find_symbol", "(", "self", ",", "name", "=", "None", ",", "kind", "=", "None", ")", ":", "for", "s", "in", "reversed", "(", "self", ".", "stack", ")", ":", "for", "symbol_name", ",", "handle", "in", "s", ".", "symbols", ".", "items", "(", ")", ":", "symbol_kind", "=", "handle", ".", "__class__", ".", "__name__", "if", "name", "==", "symbol_name", "and", "kind", "==", "symbol_kind", ":", "return", "handle", "elif", "name", "is", "None", "and", "kind", "==", "handle", ".", "__class__", ".", "__name__", ":", "return", "handle", "elif", "name", "==", "symbol_name", "and", "kind", "is", "None", ":", "return", "handle", "if", "name", "is", "None", "and", "kind", "==", "s", ".", "handle", ".", "__class__", ".", "__name__", ":", "return", "s", ".", "handle" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
Contacts.update_membership
input: gdata ContactEntry and GroupEntry objects
comdev/google_api.py
def update_membership(self, contact, group): ''' input: gdata ContactEntry and GroupEntry objects ''' if not contact: log.debug('Not updating membership for EMPTY contact.') return None _uid = contact.email[0].address _gtitle = group.title.text for contact_group in contact.group_membership_info: if contact_group.href == group.get_id(): log.warn( ' ... {} already a member of {}.'.format(_uid, _gtitle)) return contact log.debug('Adding {} to group {}'.format(_uid, _gtitle)) membership = self.api.contacts.data.GroupMembershipInfo( href=group.id.text) contact.group_membership_info.append(membership) contact = self.api.update(contact) return contact
def update_membership(self, contact, group): ''' input: gdata ContactEntry and GroupEntry objects ''' if not contact: log.debug('Not updating membership for EMPTY contact.') return None _uid = contact.email[0].address _gtitle = group.title.text for contact_group in contact.group_membership_info: if contact_group.href == group.get_id(): log.warn( ' ... {} already a member of {}.'.format(_uid, _gtitle)) return contact log.debug('Adding {} to group {}'.format(_uid, _gtitle)) membership = self.api.contacts.data.GroupMembershipInfo( href=group.id.text) contact.group_membership_info.append(membership) contact = self.api.update(contact) return contact
[ "input", ":", "gdata", "ContactEntry", "and", "GroupEntry", "objects" ]
kejbaly2/comdev
python
https://github.com/kejbaly2/comdev/blob/5a9067d3c1ae46eeccb9d36e8c231ea5224b42b4/comdev/google_api.py#L184-L205
[ "def", "update_membership", "(", "self", ",", "contact", ",", "group", ")", ":", "if", "not", "contact", ":", "log", ".", "debug", "(", "'Not updating membership for EMPTY contact.'", ")", "return", "None", "_uid", "=", "contact", ".", "email", "[", "0", "]", ".", "address", "_gtitle", "=", "group", ".", "title", ".", "text", "for", "contact_group", "in", "contact", ".", "group_membership_info", ":", "if", "contact_group", ".", "href", "==", "group", ".", "get_id", "(", ")", ":", "log", ".", "warn", "(", "' ... {} already a member of {}.'", ".", "format", "(", "_uid", ",", "_gtitle", ")", ")", "return", "contact", "log", ".", "debug", "(", "'Adding {} to group {}'", ".", "format", "(", "_uid", ",", "_gtitle", ")", ")", "membership", "=", "self", ".", "api", ".", "contacts", ".", "data", ".", "GroupMembershipInfo", "(", "href", "=", "group", ".", "id", ".", "text", ")", "contact", ".", "group_membership_info", ".", "append", "(", "membership", ")", "contact", "=", "self", ".", "api", ".", "update", "(", "contact", ")", "return", "contact" ]
5a9067d3c1ae46eeccb9d36e8c231ea5224b42b4
test
is_contained_in
Determine if a PE_PE is contained within a EP_PKG or a C_C.
bridgepoint/ooaofooa.py
def is_contained_in(pe_pe, root): ''' Determine if a PE_PE is contained within a EP_PKG or a C_C. ''' if not pe_pe: return False if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() ep_pkg = one(pe_pe).EP_PKG[8000]() c_c = one(pe_pe).C_C[8003]() if root in [ep_pkg, c_c]: return True elif is_contained_in(ep_pkg, root): return True elif is_contained_in(c_c, root): return True else: return False
def is_contained_in(pe_pe, root): ''' Determine if a PE_PE is contained within a EP_PKG or a C_C. ''' if not pe_pe: return False if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() ep_pkg = one(pe_pe).EP_PKG[8000]() c_c = one(pe_pe).C_C[8003]() if root in [ep_pkg, c_c]: return True elif is_contained_in(ep_pkg, root): return True elif is_contained_in(c_c, root): return True else: return False
[ "Determine", "if", "a", "PE_PE", "is", "contained", "within", "a", "EP_PKG", "or", "a", "C_C", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L63-L86
[ "def", "is_contained_in", "(", "pe_pe", ",", "root", ")", ":", "if", "not", "pe_pe", ":", "return", "False", "if", "type", "(", "pe_pe", ")", ".", "__name__", "!=", "'PE_PE'", ":", "pe_pe", "=", "one", "(", "pe_pe", ")", ".", "PE_PE", "[", "8001", "]", "(", ")", "ep_pkg", "=", "one", "(", "pe_pe", ")", ".", "EP_PKG", "[", "8000", "]", "(", ")", "c_c", "=", "one", "(", "pe_pe", ")", ".", "C_C", "[", "8003", "]", "(", ")", "if", "root", "in", "[", "ep_pkg", ",", "c_c", "]", ":", "return", "True", "elif", "is_contained_in", "(", "ep_pkg", ",", "root", ")", ":", "return", "True", "elif", "is_contained_in", "(", "c_c", ",", "root", ")", ":", "return", "True", "else", ":", "return", "False" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
is_global
Check if a PE_PE is globally defined, i.e. not inside a C_C
bridgepoint/ooaofooa.py
def is_global(pe_pe): ''' Check if a PE_PE is globally defined, i.e. not inside a C_C ''' if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() if one(pe_pe).C_C[8003](): return False pe_pe = one(pe_pe).EP_PKG[8000].PE_PE[8001]() if not pe_pe: return True return is_global(pe_pe)
def is_global(pe_pe): ''' Check if a PE_PE is globally defined, i.e. not inside a C_C ''' if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() if one(pe_pe).C_C[8003](): return False pe_pe = one(pe_pe).EP_PKG[8000].PE_PE[8001]() if not pe_pe: return True return is_global(pe_pe)
[ "Check", "if", "a", "PE_PE", "is", "globally", "defined", "i", ".", "e", ".", "not", "inside", "a", "C_C" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L89-L103
[ "def", "is_global", "(", "pe_pe", ")", ":", "if", "type", "(", "pe_pe", ")", ".", "__name__", "!=", "'PE_PE'", ":", "pe_pe", "=", "one", "(", "pe_pe", ")", ".", "PE_PE", "[", "8001", "]", "(", ")", "if", "one", "(", "pe_pe", ")", ".", "C_C", "[", "8003", "]", "(", ")", ":", "return", "False", "pe_pe", "=", "one", "(", "pe_pe", ")", ".", "EP_PKG", "[", "8000", "]", ".", "PE_PE", "[", "8001", "]", "(", ")", "if", "not", "pe_pe", ":", "return", "True", "return", "is_global", "(", "pe_pe", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
get_defining_component
Get the BridgePoint component (C_C) that defines the packeable element *pe_pe*.
bridgepoint/ooaofooa.py
def get_defining_component(pe_pe): ''' Get the BridgePoint component (C_C) that defines the packeable element *pe_pe*. ''' if pe_pe is None: return None if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() ep_pkg = one(pe_pe).EP_PKG[8000]() if ep_pkg: return get_defining_component(ep_pkg) return one(pe_pe).C_C[8003]()
def get_defining_component(pe_pe): ''' Get the BridgePoint component (C_C) that defines the packeable element *pe_pe*. ''' if pe_pe is None: return None if type(pe_pe).__name__ != 'PE_PE': pe_pe = one(pe_pe).PE_PE[8001]() ep_pkg = one(pe_pe).EP_PKG[8000]() if ep_pkg: return get_defining_component(ep_pkg) return one(pe_pe).C_C[8003]()
[ "Get", "the", "BridgePoint", "component", "(", "C_C", ")", "that", "defines", "the", "packeable", "element", "*", "pe_pe", "*", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L106-L121
[ "def", "get_defining_component", "(", "pe_pe", ")", ":", "if", "pe_pe", "is", "None", ":", "return", "None", "if", "type", "(", "pe_pe", ")", ".", "__name__", "!=", "'PE_PE'", ":", "pe_pe", "=", "one", "(", "pe_pe", ")", ".", "PE_PE", "[", "8001", "]", "(", ")", "ep_pkg", "=", "one", "(", "pe_pe", ")", ".", "EP_PKG", "[", "8000", "]", "(", ")", "if", "ep_pkg", ":", "return", "get_defining_component", "(", "ep_pkg", ")", "return", "one", "(", "pe_pe", ")", ".", "C_C", "[", "8003", "]", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
get_attribute_type
Get the base data type (S_DT) associated with a BridgePoint attribute.
bridgepoint/ooaofooa.py
def get_attribute_type(o_attr): ''' Get the base data type (S_DT) associated with a BridgePoint attribute. ''' ref_o_attr = one(o_attr).O_RATTR[106].O_BATTR[113].O_ATTR[106]() if ref_o_attr: return get_attribute_type(ref_o_attr) else: return one(o_attr).S_DT[114]()
def get_attribute_type(o_attr): ''' Get the base data type (S_DT) associated with a BridgePoint attribute. ''' ref_o_attr = one(o_attr).O_RATTR[106].O_BATTR[113].O_ATTR[106]() if ref_o_attr: return get_attribute_type(ref_o_attr) else: return one(o_attr).S_DT[114]()
[ "Get", "the", "base", "data", "type", "(", "S_DT", ")", "associated", "with", "a", "BridgePoint", "attribute", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L124-L132
[ "def", "get_attribute_type", "(", "o_attr", ")", ":", "ref_o_attr", "=", "one", "(", "o_attr", ")", ".", "O_RATTR", "[", "106", "]", ".", "O_BATTR", "[", "113", "]", ".", "O_ATTR", "[", "106", "]", "(", ")", "if", "ref_o_attr", ":", "return", "get_attribute_type", "(", "ref_o_attr", ")", "else", ":", "return", "one", "(", "o_attr", ")", ".", "S_DT", "[", "114", "]", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
_get_data_type_name
Convert a BridgePoint data type to a pyxtuml meta model type.
bridgepoint/ooaofooa.py
def _get_data_type_name(s_dt): ''' Convert a BridgePoint data type to a pyxtuml meta model type. ''' s_cdt = one(s_dt).S_CDT[17]() if s_cdt and s_cdt.Core_Typ in range(1, 6): return s_dt.Name.upper() if one(s_dt).S_EDT[17](): return 'INTEGER' s_dt = one(s_dt).S_UDT[17].S_DT[18]() if s_dt: return _get_data_type_name(s_dt)
def _get_data_type_name(s_dt): ''' Convert a BridgePoint data type to a pyxtuml meta model type. ''' s_cdt = one(s_dt).S_CDT[17]() if s_cdt and s_cdt.Core_Typ in range(1, 6): return s_dt.Name.upper() if one(s_dt).S_EDT[17](): return 'INTEGER' s_dt = one(s_dt).S_UDT[17].S_DT[18]() if s_dt: return _get_data_type_name(s_dt)
[ "Convert", "a", "BridgePoint", "data", "type", "to", "a", "pyxtuml", "meta", "model", "type", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L135-L148
[ "def", "_get_data_type_name", "(", "s_dt", ")", ":", "s_cdt", "=", "one", "(", "s_dt", ")", ".", "S_CDT", "[", "17", "]", "(", ")", "if", "s_cdt", "and", "s_cdt", ".", "Core_Typ", "in", "range", "(", "1", ",", "6", ")", ":", "return", "s_dt", ".", "Name", ".", "upper", "(", ")", "if", "one", "(", "s_dt", ")", ".", "S_EDT", "[", "17", "]", "(", ")", ":", "return", "'INTEGER'", "s_dt", "=", "one", "(", "s_dt", ")", ".", "S_UDT", "[", "17", "]", ".", "S_DT", "[", "18", "]", "(", ")", "if", "s_dt", ":", "return", "_get_data_type_name", "(", "s_dt", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
_get_related_attributes
The two lists of attributes which relates two classes in an association.
bridgepoint/ooaofooa.py
def _get_related_attributes(r_rgo, r_rto): ''' The two lists of attributes which relates two classes in an association. ''' l1 = list() l2 = list() ref_filter = lambda ref: ref.OIR_ID == r_rgo.OIR_ID for o_ref in many(r_rto).O_RTIDA[110].O_REF[111](ref_filter): o_attr = one(o_ref).O_RATTR[108].O_ATTR[106]() l1.append(o_attr.Name) o_attr = one(o_ref).O_RTIDA[111].O_OIDA[110].O_ATTR[105]() l2.append(o_attr.Name) return l1, l2
def _get_related_attributes(r_rgo, r_rto): ''' The two lists of attributes which relates two classes in an association. ''' l1 = list() l2 = list() ref_filter = lambda ref: ref.OIR_ID == r_rgo.OIR_ID for o_ref in many(r_rto).O_RTIDA[110].O_REF[111](ref_filter): o_attr = one(o_ref).O_RATTR[108].O_ATTR[106]() l1.append(o_attr.Name) o_attr = one(o_ref).O_RTIDA[111].O_OIDA[110].O_ATTR[105]() l2.append(o_attr.Name) return l1, l2
[ "The", "two", "lists", "of", "attributes", "which", "relates", "two", "classes", "in", "an", "association", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L151-L166
[ "def", "_get_related_attributes", "(", "r_rgo", ",", "r_rto", ")", ":", "l1", "=", "list", "(", ")", "l2", "=", "list", "(", ")", "ref_filter", "=", "lambda", "ref", ":", "ref", ".", "OIR_ID", "==", "r_rgo", ".", "OIR_ID", "for", "o_ref", "in", "many", "(", "r_rto", ")", ".", "O_RTIDA", "[", "110", "]", ".", "O_REF", "[", "111", "]", "(", "ref_filter", ")", ":", "o_attr", "=", "one", "(", "o_ref", ")", ".", "O_RATTR", "[", "108", "]", ".", "O_ATTR", "[", "106", "]", "(", ")", "l1", ".", "append", "(", "o_attr", ".", "Name", ")", "o_attr", "=", "one", "(", "o_ref", ")", ".", "O_RTIDA", "[", "111", "]", ".", "O_OIDA", "[", "110", "]", ".", "O_ATTR", "[", "105", "]", "(", ")", "l2", ".", "append", "(", "o_attr", ".", "Name", ")", "return", "l1", ",", "l2" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_enum
Create a named tuple from a BridgePoint enumeration.
bridgepoint/ooaofooa.py
def mk_enum(s_edt): ''' Create a named tuple from a BridgePoint enumeration. ''' s_dt = one(s_edt).S_DT[17]() enums = list() kwlist =['False', 'None', 'True'] + keyword.kwlist for enum in many(s_edt).S_ENUM[27](): if enum.Name in kwlist: enums.append(enum.Name + '_') else: enums.append(enum.Name) Enum = collections.namedtuple(s_dt.Name, enums) return Enum(*range(len(enums)))
def mk_enum(s_edt): ''' Create a named tuple from a BridgePoint enumeration. ''' s_dt = one(s_edt).S_DT[17]() enums = list() kwlist =['False', 'None', 'True'] + keyword.kwlist for enum in many(s_edt).S_ENUM[27](): if enum.Name in kwlist: enums.append(enum.Name + '_') else: enums.append(enum.Name) Enum = collections.namedtuple(s_dt.Name, enums) return Enum(*range(len(enums)))
[ "Create", "a", "named", "tuple", "from", "a", "BridgePoint", "enumeration", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L169-L183
[ "def", "mk_enum", "(", "s_edt", ")", ":", "s_dt", "=", "one", "(", "s_edt", ")", ".", "S_DT", "[", "17", "]", "(", ")", "enums", "=", "list", "(", ")", "kwlist", "=", "[", "'False'", ",", "'None'", ",", "'True'", "]", "+", "keyword", ".", "kwlist", "for", "enum", "in", "many", "(", "s_edt", ")", ".", "S_ENUM", "[", "27", "]", "(", ")", ":", "if", "enum", ".", "Name", "in", "kwlist", ":", "enums", ".", "append", "(", "enum", ".", "Name", "+", "'_'", ")", "else", ":", "enums", ".", "append", "(", "enum", ".", "Name", ")", "Enum", "=", "collections", ".", "namedtuple", "(", "s_dt", ".", "Name", ",", "enums", ")", "return", "Enum", "(", "*", "range", "(", "len", "(", "enums", ")", ")", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_bridge
Create a python function from a BridgePoint bridge.
bridgepoint/ooaofooa.py
def mk_bridge(metamodel, s_brg): ''' Create a python function from a BridgePoint bridge. ''' action = s_brg.Action_Semantics_internal label = s_brg.Name return lambda **kwargs: interpret.run_function(metamodel, label, action, kwargs)
def mk_bridge(metamodel, s_brg): ''' Create a python function from a BridgePoint bridge. ''' action = s_brg.Action_Semantics_internal label = s_brg.Name return lambda **kwargs: interpret.run_function(metamodel, label, action, kwargs)
[ "Create", "a", "python", "function", "from", "a", "BridgePoint", "bridge", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L186-L193
[ "def", "mk_bridge", "(", "metamodel", ",", "s_brg", ")", ":", "action", "=", "s_brg", ".", "Action_Semantics_internal", "label", "=", "s_brg", ".", "Name", "return", "lambda", "*", "*", "kwargs", ":", "interpret", ".", "run_function", "(", "metamodel", ",", "label", ",", "action", ",", "kwargs", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_external_entity
Create a python object from a BridgePoint external entity with bridges realized as python member functions.
bridgepoint/ooaofooa.py
def mk_external_entity(metamodel, s_ee): ''' Create a python object from a BridgePoint external entity with bridges realized as python member functions. ''' bridges = many(s_ee).S_BRG[19]() names = [brg.Name for brg in bridges] EE = collections.namedtuple(s_ee.Key_Lett, names) funcs = list() for s_brg in many(s_ee).S_BRG[19](): fn = mk_bridge(metamodel, s_brg) funcs.append(fn) return EE(*funcs)
def mk_external_entity(metamodel, s_ee): ''' Create a python object from a BridgePoint external entity with bridges realized as python member functions. ''' bridges = many(s_ee).S_BRG[19]() names = [brg.Name for brg in bridges] EE = collections.namedtuple(s_ee.Key_Lett, names) funcs = list() for s_brg in many(s_ee).S_BRG[19](): fn = mk_bridge(metamodel, s_brg) funcs.append(fn) return EE(*funcs)
[ "Create", "a", "python", "object", "from", "a", "BridgePoint", "external", "entity", "with", "bridges", "realized", "as", "python", "member", "functions", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L196-L210
[ "def", "mk_external_entity", "(", "metamodel", ",", "s_ee", ")", ":", "bridges", "=", "many", "(", "s_ee", ")", ".", "S_BRG", "[", "19", "]", "(", ")", "names", "=", "[", "brg", ".", "Name", "for", "brg", "in", "bridges", "]", "EE", "=", "collections", ".", "namedtuple", "(", "s_ee", ".", "Key_Lett", ",", "names", ")", "funcs", "=", "list", "(", ")", "for", "s_brg", "in", "many", "(", "s_ee", ")", ".", "S_BRG", "[", "19", "]", "(", ")", ":", "fn", "=", "mk_bridge", "(", "metamodel", ",", "s_brg", ")", "funcs", ".", "append", "(", "fn", ")", "return", "EE", "(", "*", "funcs", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_function
Create a python function from a BridgePoint function.
bridgepoint/ooaofooa.py
def mk_function(metamodel, s_sync): ''' Create a python function from a BridgePoint function. ''' action = s_sync.Action_Semantics_internal label = s_sync.Name return lambda **kwargs: interpret.run_function(metamodel, label, action, kwargs)
def mk_function(metamodel, s_sync): ''' Create a python function from a BridgePoint function. ''' action = s_sync.Action_Semantics_internal label = s_sync.Name return lambda **kwargs: interpret.run_function(metamodel, label, action, kwargs)
[ "Create", "a", "python", "function", "from", "a", "BridgePoint", "function", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L213-L220
[ "def", "mk_function", "(", "metamodel", ",", "s_sync", ")", ":", "action", "=", "s_sync", ".", "Action_Semantics_internal", "label", "=", "s_sync", ".", "Name", "return", "lambda", "*", "*", "kwargs", ":", "interpret", ".", "run_function", "(", "metamodel", ",", "label", ",", "action", ",", "kwargs", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_constant
Create a python value from a BridgePoint constant.
bridgepoint/ooaofooa.py
def mk_constant(cnst_syc): ''' Create a python value from a BridgePoint constant. ''' s_dt = one(cnst_syc).S_DT[1500]() cnst_lsc = one(cnst_syc).CNST_LFSC[1502].CNST_LSC[1503]() if s_dt.Name == 'boolean': return cnst_lsc.Value.lower() == 'true' if s_dt.Name == 'integer': return int(cnst_lsc.Value) if s_dt.Name == 'real': return float(cnst_lsc.Value) if s_dt.Name == 'string': return str(cnst_lsc.Value)
def mk_constant(cnst_syc): ''' Create a python value from a BridgePoint constant. ''' s_dt = one(cnst_syc).S_DT[1500]() cnst_lsc = one(cnst_syc).CNST_LFSC[1502].CNST_LSC[1503]() if s_dt.Name == 'boolean': return cnst_lsc.Value.lower() == 'true' if s_dt.Name == 'integer': return int(cnst_lsc.Value) if s_dt.Name == 'real': return float(cnst_lsc.Value) if s_dt.Name == 'string': return str(cnst_lsc.Value)
[ "Create", "a", "python", "value", "from", "a", "BridgePoint", "constant", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L223-L240
[ "def", "mk_constant", "(", "cnst_syc", ")", ":", "s_dt", "=", "one", "(", "cnst_syc", ")", ".", "S_DT", "[", "1500", "]", "(", ")", "cnst_lsc", "=", "one", "(", "cnst_syc", ")", ".", "CNST_LFSC", "[", "1502", "]", ".", "CNST_LSC", "[", "1503", "]", "(", ")", "if", "s_dt", ".", "Name", "==", "'boolean'", ":", "return", "cnst_lsc", ".", "Value", ".", "lower", "(", ")", "==", "'true'", "if", "s_dt", ".", "Name", "==", "'integer'", ":", "return", "int", "(", "cnst_lsc", ".", "Value", ")", "if", "s_dt", ".", "Name", "==", "'real'", ":", "return", "float", "(", "cnst_lsc", ".", "Value", ")", "if", "s_dt", ".", "Name", "==", "'string'", ":", "return", "str", "(", "cnst_lsc", ".", "Value", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_operation
Create a python function that interprets that action of a BridgePoint class operation.
bridgepoint/ooaofooa.py
def mk_operation(metaclass, o_tfr): ''' Create a python function that interprets that action of a BridgePoint class operation. ''' o_obj = one(o_tfr).O_OBJ[115]() action = o_tfr.Action_Semantics_internal label = '%s::%s' % (o_obj.Name, o_tfr.Name) run = interpret.run_operation if o_tfr.Instance_Based: return lambda self, **kwargs: run(metaclass, label, action, kwargs, self) else: fn = lambda cls, **kwargs: run(metaclass, label, action, kwargs, None) return classmethod(fn)
def mk_operation(metaclass, o_tfr): ''' Create a python function that interprets that action of a BridgePoint class operation. ''' o_obj = one(o_tfr).O_OBJ[115]() action = o_tfr.Action_Semantics_internal label = '%s::%s' % (o_obj.Name, o_tfr.Name) run = interpret.run_operation if o_tfr.Instance_Based: return lambda self, **kwargs: run(metaclass, label, action, kwargs, self) else: fn = lambda cls, **kwargs: run(metaclass, label, action, kwargs, None) return classmethod(fn)
[ "Create", "a", "python", "function", "that", "interprets", "that", "action", "of", "a", "BridgePoint", "class", "operation", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L243-L257
[ "def", "mk_operation", "(", "metaclass", ",", "o_tfr", ")", ":", "o_obj", "=", "one", "(", "o_tfr", ")", ".", "O_OBJ", "[", "115", "]", "(", ")", "action", "=", "o_tfr", ".", "Action_Semantics_internal", "label", "=", "'%s::%s'", "%", "(", "o_obj", ".", "Name", ",", "o_tfr", ".", "Name", ")", "run", "=", "interpret", ".", "run_operation", "if", "o_tfr", ".", "Instance_Based", ":", "return", "lambda", "self", ",", "*", "*", "kwargs", ":", "run", "(", "metaclass", ",", "label", ",", "action", ",", "kwargs", ",", "self", ")", "else", ":", "fn", "=", "lambda", "cls", ",", "*", "*", "kwargs", ":", "run", "(", "metaclass", ",", "label", ",", "action", ",", "kwargs", ",", "None", ")", "return", "classmethod", "(", "fn", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_derived_attribute
Create a python property that interprets that action of a BridgePoint derived attribute.
bridgepoint/ooaofooa.py
def mk_derived_attribute(metaclass, o_dbattr): ''' Create a python property that interprets that action of a BridgePoint derived attribute. ''' o_attr = one(o_dbattr).O_BATTR[107].O_ATTR[106]() o_obj = one(o_attr).O_OBJ[102]() action = o_dbattr.Action_Semantics_internal label = '%s::%s' % (o_obj.Name, o_attr.Name) fget = functools.partial(interpret.run_derived_attribute, metaclass, label, action, o_attr.Name) return property(fget)
def mk_derived_attribute(metaclass, o_dbattr): ''' Create a python property that interprets that action of a BridgePoint derived attribute. ''' o_attr = one(o_dbattr).O_BATTR[107].O_ATTR[106]() o_obj = one(o_attr).O_OBJ[102]() action = o_dbattr.Action_Semantics_internal label = '%s::%s' % (o_obj.Name, o_attr.Name) fget = functools.partial(interpret.run_derived_attribute, metaclass, label, action, o_attr.Name) return property(fget)
[ "Create", "a", "python", "property", "that", "interprets", "that", "action", "of", "a", "BridgePoint", "derived", "attribute", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L260-L271
[ "def", "mk_derived_attribute", "(", "metaclass", ",", "o_dbattr", ")", ":", "o_attr", "=", "one", "(", "o_dbattr", ")", ".", "O_BATTR", "[", "107", "]", ".", "O_ATTR", "[", "106", "]", "(", ")", "o_obj", "=", "one", "(", "o_attr", ")", ".", "O_OBJ", "[", "102", "]", "(", ")", "action", "=", "o_dbattr", ".", "Action_Semantics_internal", "label", "=", "'%s::%s'", "%", "(", "o_obj", ".", "Name", ",", "o_attr", ".", "Name", ")", "fget", "=", "functools", ".", "partial", "(", "interpret", ".", "run_derived_attribute", ",", "metaclass", ",", "label", ",", "action", ",", "o_attr", ".", "Name", ")", "return", "property", "(", "fget", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_class
Create a pyxtuml class from a BridgePoint class.
bridgepoint/ooaofooa.py
def mk_class(m, o_obj, derived_attributes=False): ''' Create a pyxtuml class from a BridgePoint class. ''' first_filter = lambda selected: not one(selected).O_ATTR[103, 'succeeds']() o_attr = one(o_obj).O_ATTR[102](first_filter) attributes = list() while o_attr: s_dt = get_attribute_type(o_attr) ty = _get_data_type_name(s_dt) if not derived_attributes and one(o_attr).O_BATTR[106].O_DBATTR[107](): pass # logger.warning('Omitting derived attribute %s.%s ' % # (o_obj.Key_Lett, o_attr.Name)) elif not ty: logger.warning('Omitting unsupported attribute %s.%s ' % (o_obj.Key_Lett, o_attr.Name)) else: attributes.append((o_attr.Name, ty)) o_attr = one(o_attr).O_ATTR[103, 'precedes']() metaclass = m.define_class(o_obj.Key_Lett, list(attributes), o_obj.Descrip) for o_id in many(o_obj).O_ID[104](): o_oida = many(o_id).O_OIDA[105]() o_attrs = many(o_oida).O_ATTR[105]() if not derived_attributes and one(o_attrs).O_BATTR[106].O_DBATTR[107](): logger.warning('Omitting unique identifier %s.I%d' % (o_obj.Key_Lett, o_id.Oid_ID + 1)) continue names = [o_attr.Name for o_attr in o_attrs] m.define_unique_identifier(o_obj.Key_Lett, o_id.Oid_ID + 1, *names) for o_tfr in many(o_obj).O_TFR[115](): fn = mk_operation(metaclass, o_tfr) setattr(metaclass.clazz, o_tfr.Name, fn) for o_dbattr in many(o_obj).O_ATTR[102].O_BATTR[106].O_DBATTR[107](): o_attr = one(o_dbattr).O_BATTR[107].O_ATTR[106]() fn = mk_derived_attribute(metaclass, o_dbattr) setattr(metaclass.clazz, o_attr.Name, fn) return metaclass
def mk_class(m, o_obj, derived_attributes=False): ''' Create a pyxtuml class from a BridgePoint class. ''' first_filter = lambda selected: not one(selected).O_ATTR[103, 'succeeds']() o_attr = one(o_obj).O_ATTR[102](first_filter) attributes = list() while o_attr: s_dt = get_attribute_type(o_attr) ty = _get_data_type_name(s_dt) if not derived_attributes and one(o_attr).O_BATTR[106].O_DBATTR[107](): pass # logger.warning('Omitting derived attribute %s.%s ' % # (o_obj.Key_Lett, o_attr.Name)) elif not ty: logger.warning('Omitting unsupported attribute %s.%s ' % (o_obj.Key_Lett, o_attr.Name)) else: attributes.append((o_attr.Name, ty)) o_attr = one(o_attr).O_ATTR[103, 'precedes']() metaclass = m.define_class(o_obj.Key_Lett, list(attributes), o_obj.Descrip) for o_id in many(o_obj).O_ID[104](): o_oida = many(o_id).O_OIDA[105]() o_attrs = many(o_oida).O_ATTR[105]() if not derived_attributes and one(o_attrs).O_BATTR[106].O_DBATTR[107](): logger.warning('Omitting unique identifier %s.I%d' % (o_obj.Key_Lett, o_id.Oid_ID + 1)) continue names = [o_attr.Name for o_attr in o_attrs] m.define_unique_identifier(o_obj.Key_Lett, o_id.Oid_ID + 1, *names) for o_tfr in many(o_obj).O_TFR[115](): fn = mk_operation(metaclass, o_tfr) setattr(metaclass.clazz, o_tfr.Name, fn) for o_dbattr in many(o_obj).O_ATTR[102].O_BATTR[106].O_DBATTR[107](): o_attr = one(o_dbattr).O_BATTR[107].O_ATTR[106]() fn = mk_derived_attribute(metaclass, o_dbattr) setattr(metaclass.clazz, o_attr.Name, fn) return metaclass
[ "Create", "a", "pyxtuml", "class", "from", "a", "BridgePoint", "class", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L274-L319
[ "def", "mk_class", "(", "m", ",", "o_obj", ",", "derived_attributes", "=", "False", ")", ":", "first_filter", "=", "lambda", "selected", ":", "not", "one", "(", "selected", ")", ".", "O_ATTR", "[", "103", ",", "'succeeds'", "]", "(", ")", "o_attr", "=", "one", "(", "o_obj", ")", ".", "O_ATTR", "[", "102", "]", "(", "first_filter", ")", "attributes", "=", "list", "(", ")", "while", "o_attr", ":", "s_dt", "=", "get_attribute_type", "(", "o_attr", ")", "ty", "=", "_get_data_type_name", "(", "s_dt", ")", "if", "not", "derived_attributes", "and", "one", "(", "o_attr", ")", ".", "O_BATTR", "[", "106", "]", ".", "O_DBATTR", "[", "107", "]", "(", ")", ":", "pass", "# logger.warning('Omitting derived attribute %s.%s ' %", "# (o_obj.Key_Lett, o_attr.Name))", "elif", "not", "ty", ":", "logger", ".", "warning", "(", "'Omitting unsupported attribute %s.%s '", "%", "(", "o_obj", ".", "Key_Lett", ",", "o_attr", ".", "Name", ")", ")", "else", ":", "attributes", ".", "append", "(", "(", "o_attr", ".", "Name", ",", "ty", ")", ")", "o_attr", "=", "one", "(", "o_attr", ")", ".", "O_ATTR", "[", "103", ",", "'precedes'", "]", "(", ")", "metaclass", "=", "m", ".", "define_class", "(", "o_obj", ".", "Key_Lett", ",", "list", "(", "attributes", ")", ",", "o_obj", ".", "Descrip", ")", "for", "o_id", "in", "many", "(", "o_obj", ")", ".", "O_ID", "[", "104", "]", "(", ")", ":", "o_oida", "=", "many", "(", "o_id", ")", ".", "O_OIDA", "[", "105", "]", "(", ")", "o_attrs", "=", "many", "(", "o_oida", ")", ".", "O_ATTR", "[", "105", "]", "(", ")", "if", "not", "derived_attributes", "and", "one", "(", "o_attrs", ")", ".", "O_BATTR", "[", "106", "]", ".", "O_DBATTR", "[", "107", "]", "(", ")", ":", "logger", ".", "warning", "(", "'Omitting unique identifier %s.I%d'", "%", "(", "o_obj", ".", "Key_Lett", ",", "o_id", ".", "Oid_ID", "+", "1", ")", ")", "continue", "names", "=", "[", "o_attr", ".", "Name", "for", "o_attr", "in", "o_attrs", "]", "m", ".", "define_unique_identifier", "(", "o_obj", ".", "Key_Lett", ",", "o_id", ".", "Oid_ID", "+", "1", ",", "*", "names", ")", "for", "o_tfr", "in", "many", "(", "o_obj", ")", ".", "O_TFR", "[", "115", "]", "(", ")", ":", "fn", "=", "mk_operation", "(", "metaclass", ",", "o_tfr", ")", "setattr", "(", "metaclass", ".", "clazz", ",", "o_tfr", ".", "Name", ",", "fn", ")", "for", "o_dbattr", "in", "many", "(", "o_obj", ")", ".", "O_ATTR", "[", "102", "]", ".", "O_BATTR", "[", "106", "]", ".", "O_DBATTR", "[", "107", "]", "(", ")", ":", "o_attr", "=", "one", "(", "o_dbattr", ")", ".", "O_BATTR", "[", "107", "]", ".", "O_ATTR", "[", "106", "]", "(", ")", "fn", "=", "mk_derived_attribute", "(", "metaclass", ",", "o_dbattr", ")", "setattr", "(", "metaclass", ".", "clazz", ",", "o_attr", ".", "Name", ",", "fn", ")", "return", "metaclass" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_simple_association
Create a pyxtuml association from a simple association in BridgePoint.
bridgepoint/ooaofooa.py
def mk_simple_association(m, r_simp): ''' Create a pyxtuml association from a simple association in BridgePoint. ''' r_rel = one(r_simp).R_REL[206]() r_form = one(r_simp).R_FORM[208]() r_part = one(r_simp).R_PART[207]() r_rgo = one(r_form).R_RGO[205]() r_rto = one(r_part).R_RTO[204]() if not r_form: logger.info('unformalized association R%s' % (r_rel.Numb)) r_form = one(r_simp).R_PART[207](lambda sel: sel != r_part) r_rgo = one(r_form).R_RTO[204]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) if source_o_obj.Obj_ID != target_o_obj.Obj_ID: source_phrase = target_phrase = '' else: source_phrase = r_part.Txt_Phrs target_phrase = r_form.Txt_Phrs m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=r_form.Cond, target_conditional=r_part.Cond, source_phrase=source_phrase, target_phrase=target_phrase, source_many=r_form.Mult, target_many=r_part.Mult)
def mk_simple_association(m, r_simp): ''' Create a pyxtuml association from a simple association in BridgePoint. ''' r_rel = one(r_simp).R_REL[206]() r_form = one(r_simp).R_FORM[208]() r_part = one(r_simp).R_PART[207]() r_rgo = one(r_form).R_RGO[205]() r_rto = one(r_part).R_RTO[204]() if not r_form: logger.info('unformalized association R%s' % (r_rel.Numb)) r_form = one(r_simp).R_PART[207](lambda sel: sel != r_part) r_rgo = one(r_form).R_RTO[204]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) if source_o_obj.Obj_ID != target_o_obj.Obj_ID: source_phrase = target_phrase = '' else: source_phrase = r_part.Txt_Phrs target_phrase = r_form.Txt_Phrs m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=r_form.Cond, target_conditional=r_part.Cond, source_phrase=source_phrase, target_phrase=target_phrase, source_many=r_form.Mult, target_many=r_part.Mult)
[ "Create", "a", "pyxtuml", "association", "from", "a", "simple", "association", "in", "BridgePoint", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L322-L359
[ "def", "mk_simple_association", "(", "m", ",", "r_simp", ")", ":", "r_rel", "=", "one", "(", "r_simp", ")", ".", "R_REL", "[", "206", "]", "(", ")", "r_form", "=", "one", "(", "r_simp", ")", ".", "R_FORM", "[", "208", "]", "(", ")", "r_part", "=", "one", "(", "r_simp", ")", ".", "R_PART", "[", "207", "]", "(", ")", "r_rgo", "=", "one", "(", "r_form", ")", ".", "R_RGO", "[", "205", "]", "(", ")", "r_rto", "=", "one", "(", "r_part", ")", ".", "R_RTO", "[", "204", "]", "(", ")", "if", "not", "r_form", ":", "logger", ".", "info", "(", "'unformalized association R%s'", "%", "(", "r_rel", ".", "Numb", ")", ")", "r_form", "=", "one", "(", "r_simp", ")", ".", "R_PART", "[", "207", "]", "(", "lambda", "sel", ":", "sel", "!=", "r_part", ")", "r_rgo", "=", "one", "(", "r_form", ")", ".", "R_RTO", "[", "204", "]", "(", ")", "source_o_obj", "=", "one", "(", "r_rgo", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "target_o_obj", "=", "one", "(", "r_rto", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "source_ids", ",", "target_ids", "=", "_get_related_attributes", "(", "r_rgo", ",", "r_rto", ")", "if", "source_o_obj", ".", "Obj_ID", "!=", "target_o_obj", ".", "Obj_ID", ":", "source_phrase", "=", "target_phrase", "=", "''", "else", ":", "source_phrase", "=", "r_part", ".", "Txt_Phrs", "target_phrase", "=", "r_form", ".", "Txt_Phrs", "m", ".", "define_association", "(", "rel_id", "=", "r_rel", ".", "Numb", ",", "source_kind", "=", "source_o_obj", ".", "Key_Lett", ",", "target_kind", "=", "target_o_obj", ".", "Key_Lett", ",", "source_keys", "=", "source_ids", ",", "target_keys", "=", "target_ids", ",", "source_conditional", "=", "r_form", ".", "Cond", ",", "target_conditional", "=", "r_part", ".", "Cond", ",", "source_phrase", "=", "source_phrase", ",", "target_phrase", "=", "target_phrase", ",", "source_many", "=", "r_form", ".", "Mult", ",", "target_many", "=", "r_part", ".", "Mult", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_linked_association
Create pyxtuml associations from a linked association in BridgePoint.
bridgepoint/ooaofooa.py
def mk_linked_association(m, r_assoc): ''' Create pyxtuml associations from a linked association in BridgePoint. ''' r_rel = one(r_assoc).R_REL[206]() r_rgo = one(r_assoc).R_ASSR[211].R_RGO[205]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() def _mk_assoc(side1, side2): r_rto = one(side1).R_RTO[204]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) if side1.Obj_ID != side2.Obj_ID: source_phrase = target_phrase = '' else: source_phrase = side1.Txt_Phrs target_phrase = side2.Txt_Phrs m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=side2.Cond, target_conditional=False, source_phrase=source_phrase, target_phrase=target_phrase, source_many=side2.Mult, target_many=False) r_aone = one(r_assoc).R_AONE[209]() r_aoth = one(r_assoc).R_AOTH[210]() _mk_assoc(r_aone, r_aoth) _mk_assoc(r_aoth, r_aone)
def mk_linked_association(m, r_assoc): ''' Create pyxtuml associations from a linked association in BridgePoint. ''' r_rel = one(r_assoc).R_REL[206]() r_rgo = one(r_assoc).R_ASSR[211].R_RGO[205]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() def _mk_assoc(side1, side2): r_rto = one(side1).R_RTO[204]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) if side1.Obj_ID != side2.Obj_ID: source_phrase = target_phrase = '' else: source_phrase = side1.Txt_Phrs target_phrase = side2.Txt_Phrs m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=side2.Cond, target_conditional=False, source_phrase=source_phrase, target_phrase=target_phrase, source_many=side2.Mult, target_many=False) r_aone = one(r_assoc).R_AONE[209]() r_aoth = one(r_assoc).R_AOTH[210]() _mk_assoc(r_aone, r_aoth) _mk_assoc(r_aoth, r_aone)
[ "Create", "pyxtuml", "associations", "from", "a", "linked", "association", "in", "BridgePoint", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L362-L397
[ "def", "mk_linked_association", "(", "m", ",", "r_assoc", ")", ":", "r_rel", "=", "one", "(", "r_assoc", ")", ".", "R_REL", "[", "206", "]", "(", ")", "r_rgo", "=", "one", "(", "r_assoc", ")", ".", "R_ASSR", "[", "211", "]", ".", "R_RGO", "[", "205", "]", "(", ")", "source_o_obj", "=", "one", "(", "r_rgo", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "def", "_mk_assoc", "(", "side1", ",", "side2", ")", ":", "r_rto", "=", "one", "(", "side1", ")", ".", "R_RTO", "[", "204", "]", "(", ")", "target_o_obj", "=", "one", "(", "r_rto", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "source_ids", ",", "target_ids", "=", "_get_related_attributes", "(", "r_rgo", ",", "r_rto", ")", "if", "side1", ".", "Obj_ID", "!=", "side2", ".", "Obj_ID", ":", "source_phrase", "=", "target_phrase", "=", "''", "else", ":", "source_phrase", "=", "side1", ".", "Txt_Phrs", "target_phrase", "=", "side2", ".", "Txt_Phrs", "m", ".", "define_association", "(", "rel_id", "=", "r_rel", ".", "Numb", ",", "source_kind", "=", "source_o_obj", ".", "Key_Lett", ",", "target_kind", "=", "target_o_obj", ".", "Key_Lett", ",", "source_keys", "=", "source_ids", ",", "target_keys", "=", "target_ids", ",", "source_conditional", "=", "side2", ".", "Cond", ",", "target_conditional", "=", "False", ",", "source_phrase", "=", "source_phrase", ",", "target_phrase", "=", "target_phrase", ",", "source_many", "=", "side2", ".", "Mult", ",", "target_many", "=", "False", ")", "r_aone", "=", "one", "(", "r_assoc", ")", ".", "R_AONE", "[", "209", "]", "(", ")", "r_aoth", "=", "one", "(", "r_assoc", ")", ".", "R_AOTH", "[", "210", "]", "(", ")", "_mk_assoc", "(", "r_aone", ",", "r_aoth", ")", "_mk_assoc", "(", "r_aoth", ",", "r_aone", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_subsuper_association
Create pyxtuml associations from a sub/super association in BridgePoint.
bridgepoint/ooaofooa.py
def mk_subsuper_association(m, r_subsup): ''' Create pyxtuml associations from a sub/super association in BridgePoint. ''' r_rel = one(r_subsup).R_REL[206]() r_rto = one(r_subsup).R_SUPER[212].R_RTO[204]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() for r_sub in many(r_subsup).R_SUB[213](): r_rgo = one(r_sub).R_RGO[205]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=True, target_conditional=False, source_phrase='', target_phrase='', source_many=False, target_many=False)
def mk_subsuper_association(m, r_subsup): ''' Create pyxtuml associations from a sub/super association in BridgePoint. ''' r_rel = one(r_subsup).R_REL[206]() r_rto = one(r_subsup).R_SUPER[212].R_RTO[204]() target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]() for r_sub in many(r_subsup).R_SUB[213](): r_rgo = one(r_sub).R_RGO[205]() source_o_obj = one(r_rgo).R_OIR[203].O_OBJ[201]() source_ids, target_ids = _get_related_attributes(r_rgo, r_rto) m.define_association(rel_id=r_rel.Numb, source_kind=source_o_obj.Key_Lett, target_kind=target_o_obj.Key_Lett, source_keys=source_ids, target_keys=target_ids, source_conditional=True, target_conditional=False, source_phrase='', target_phrase='', source_many=False, target_many=False)
[ "Create", "pyxtuml", "associations", "from", "a", "sub", "/", "super", "association", "in", "BridgePoint", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L400-L423
[ "def", "mk_subsuper_association", "(", "m", ",", "r_subsup", ")", ":", "r_rel", "=", "one", "(", "r_subsup", ")", ".", "R_REL", "[", "206", "]", "(", ")", "r_rto", "=", "one", "(", "r_subsup", ")", ".", "R_SUPER", "[", "212", "]", ".", "R_RTO", "[", "204", "]", "(", ")", "target_o_obj", "=", "one", "(", "r_rto", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "for", "r_sub", "in", "many", "(", "r_subsup", ")", ".", "R_SUB", "[", "213", "]", "(", ")", ":", "r_rgo", "=", "one", "(", "r_sub", ")", ".", "R_RGO", "[", "205", "]", "(", ")", "source_o_obj", "=", "one", "(", "r_rgo", ")", ".", "R_OIR", "[", "203", "]", ".", "O_OBJ", "[", "201", "]", "(", ")", "source_ids", ",", "target_ids", "=", "_get_related_attributes", "(", "r_rgo", ",", "r_rto", ")", "m", ".", "define_association", "(", "rel_id", "=", "r_rel", ".", "Numb", ",", "source_kind", "=", "source_o_obj", ".", "Key_Lett", ",", "target_kind", "=", "target_o_obj", ".", "Key_Lett", ",", "source_keys", "=", "source_ids", ",", "target_keys", "=", "target_ids", ",", "source_conditional", "=", "True", ",", "target_conditional", "=", "False", ",", "source_phrase", "=", "''", ",", "target_phrase", "=", "''", ",", "source_many", "=", "False", ",", "target_many", "=", "False", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_association
Create a pyxtuml association from a R_REL in ooaofooa.
bridgepoint/ooaofooa.py
def mk_association(m, r_rel): ''' Create a pyxtuml association from a R_REL in ooaofooa. ''' handler = { 'R_SIMP': mk_simple_association, 'R_ASSOC': mk_linked_association, 'R_SUBSUP': mk_subsuper_association, 'R_COMP': mk_derived_association, } inst = subtype(r_rel, 206) fn = handler.get(type(inst).__name__) return fn(m, inst)
def mk_association(m, r_rel): ''' Create a pyxtuml association from a R_REL in ooaofooa. ''' handler = { 'R_SIMP': mk_simple_association, 'R_ASSOC': mk_linked_association, 'R_SUBSUP': mk_subsuper_association, 'R_COMP': mk_derived_association, } inst = subtype(r_rel, 206) fn = handler.get(type(inst).__name__) return fn(m, inst)
[ "Create", "a", "pyxtuml", "association", "from", "a", "R_REL", "in", "ooaofooa", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L433-L445
[ "def", "mk_association", "(", "m", ",", "r_rel", ")", ":", "handler", "=", "{", "'R_SIMP'", ":", "mk_simple_association", ",", "'R_ASSOC'", ":", "mk_linked_association", ",", "'R_SUBSUP'", ":", "mk_subsuper_association", ",", "'R_COMP'", ":", "mk_derived_association", ",", "}", "inst", "=", "subtype", "(", "r_rel", ",", "206", ")", "fn", "=", "handler", ".", "get", "(", "type", "(", "inst", ")", ".", "__name__", ")", "return", "fn", "(", "m", ",", "inst", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
mk_component
Create a pyxtuml meta model from a BridgePoint model. Optionally, restrict to classes and associations contained in the component c_c.
bridgepoint/ooaofooa.py
def mk_component(bp_model, c_c=None, derived_attributes=False): ''' Create a pyxtuml meta model from a BridgePoint model. Optionally, restrict to classes and associations contained in the component c_c. ''' target = Domain() c_c_filt = lambda sel: c_c is None or is_contained_in(sel, c_c) for o_obj in bp_model.select_many('O_OBJ', c_c_filt): mk_class(target, o_obj, derived_attributes) for r_rel in bp_model.select_many('R_REL', c_c_filt): mk_association(target, r_rel) for s_sync in bp_model.select_many('S_SYNC', c_c_filt): fn = mk_function(target, s_sync) target.add_symbol(s_sync.Name, fn) for s_dt in bp_model.select_many('S_DT', c_c_filt): s_edt = one(s_dt).S_EDT[17]() if s_edt: enum = mk_enum(s_edt) target.add_symbol(s_dt.Name, enum) for cnst_csp in bp_model.select_many('CNST_CSP', c_c_filt): for cnst_syc in many(cnst_csp).CNST_SYC[1504](): value = mk_constant(cnst_syc) target.add_symbol(cnst_syc.Name, value) for ass in target.associations: ass.formalize() for s_ee in bp_model.select_many('S_EE', c_c_filt): if s_ee.Key_Lett in ['LOG', 'ARCH', 'TIM', 'NVS', 'PERSIST']: target.add_symbol(s_ee.Key_Lett, getattr(builtin_ee, s_ee.Key_Lett)) else: ee = mk_external_entity(target, s_ee) target.add_symbol(s_ee.Key_Lett, ee) return target
def mk_component(bp_model, c_c=None, derived_attributes=False): ''' Create a pyxtuml meta model from a BridgePoint model. Optionally, restrict to classes and associations contained in the component c_c. ''' target = Domain() c_c_filt = lambda sel: c_c is None or is_contained_in(sel, c_c) for o_obj in bp_model.select_many('O_OBJ', c_c_filt): mk_class(target, o_obj, derived_attributes) for r_rel in bp_model.select_many('R_REL', c_c_filt): mk_association(target, r_rel) for s_sync in bp_model.select_many('S_SYNC', c_c_filt): fn = mk_function(target, s_sync) target.add_symbol(s_sync.Name, fn) for s_dt in bp_model.select_many('S_DT', c_c_filt): s_edt = one(s_dt).S_EDT[17]() if s_edt: enum = mk_enum(s_edt) target.add_symbol(s_dt.Name, enum) for cnst_csp in bp_model.select_many('CNST_CSP', c_c_filt): for cnst_syc in many(cnst_csp).CNST_SYC[1504](): value = mk_constant(cnst_syc) target.add_symbol(cnst_syc.Name, value) for ass in target.associations: ass.formalize() for s_ee in bp_model.select_many('S_EE', c_c_filt): if s_ee.Key_Lett in ['LOG', 'ARCH', 'TIM', 'NVS', 'PERSIST']: target.add_symbol(s_ee.Key_Lett, getattr(builtin_ee, s_ee.Key_Lett)) else: ee = mk_external_entity(target, s_ee) target.add_symbol(s_ee.Key_Lett, ee) return target
[ "Create", "a", "pyxtuml", "meta", "model", "from", "a", "BridgePoint", "model", ".", "Optionally", "restrict", "to", "classes", "and", "associations", "contained", "in", "the", "component", "c_c", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L448-L490
[ "def", "mk_component", "(", "bp_model", ",", "c_c", "=", "None", ",", "derived_attributes", "=", "False", ")", ":", "target", "=", "Domain", "(", ")", "c_c_filt", "=", "lambda", "sel", ":", "c_c", "is", "None", "or", "is_contained_in", "(", "sel", ",", "c_c", ")", "for", "o_obj", "in", "bp_model", ".", "select_many", "(", "'O_OBJ'", ",", "c_c_filt", ")", ":", "mk_class", "(", "target", ",", "o_obj", ",", "derived_attributes", ")", "for", "r_rel", "in", "bp_model", ".", "select_many", "(", "'R_REL'", ",", "c_c_filt", ")", ":", "mk_association", "(", "target", ",", "r_rel", ")", "for", "s_sync", "in", "bp_model", ".", "select_many", "(", "'S_SYNC'", ",", "c_c_filt", ")", ":", "fn", "=", "mk_function", "(", "target", ",", "s_sync", ")", "target", ".", "add_symbol", "(", "s_sync", ".", "Name", ",", "fn", ")", "for", "s_dt", "in", "bp_model", ".", "select_many", "(", "'S_DT'", ",", "c_c_filt", ")", ":", "s_edt", "=", "one", "(", "s_dt", ")", ".", "S_EDT", "[", "17", "]", "(", ")", "if", "s_edt", ":", "enum", "=", "mk_enum", "(", "s_edt", ")", "target", ".", "add_symbol", "(", "s_dt", ".", "Name", ",", "enum", ")", "for", "cnst_csp", "in", "bp_model", ".", "select_many", "(", "'CNST_CSP'", ",", "c_c_filt", ")", ":", "for", "cnst_syc", "in", "many", "(", "cnst_csp", ")", ".", "CNST_SYC", "[", "1504", "]", "(", ")", ":", "value", "=", "mk_constant", "(", "cnst_syc", ")", "target", ".", "add_symbol", "(", "cnst_syc", ".", "Name", ",", "value", ")", "for", "ass", "in", "target", ".", "associations", ":", "ass", ".", "formalize", "(", ")", "for", "s_ee", "in", "bp_model", ".", "select_many", "(", "'S_EE'", ",", "c_c_filt", ")", ":", "if", "s_ee", ".", "Key_Lett", "in", "[", "'LOG'", ",", "'ARCH'", ",", "'TIM'", ",", "'NVS'", ",", "'PERSIST'", "]", ":", "target", ".", "add_symbol", "(", "s_ee", ".", "Key_Lett", ",", "getattr", "(", "builtin_ee", ",", "s_ee", ".", "Key_Lett", ")", ")", "else", ":", "ee", "=", "mk_external_entity", "(", "target", ",", "s_ee", ")", "target", ".", "add_symbol", "(", "s_ee", ".", "Key_Lett", ",", "ee", ")", "return", "target" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
load_metamodel
Load and return a metamodel expressed in ooaofooa from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths.
bridgepoint/ooaofooa.py
def load_metamodel(resource=None, load_globals=True): ''' Load and return a metamodel expressed in ooaofooa from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths. ''' loader = _mk_loader(resource, load_globals) return loader.build_metamodel()
def load_metamodel(resource=None, load_globals=True): ''' Load and return a metamodel expressed in ooaofooa from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths. ''' loader = _mk_loader(resource, load_globals) return loader.build_metamodel()
[ "Load", "and", "return", "a", "metamodel", "expressed", "in", "ooaofooa", "from", "a", "*", "resource", "*", ".", "The", "resource", "may", "be", "either", "a", "filename", "a", "path", "or", "a", "list", "of", "filenames", "and", "/", "or", "paths", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L557-L564
[ "def", "load_metamodel", "(", "resource", "=", "None", ",", "load_globals", "=", "True", ")", ":", "loader", "=", "_mk_loader", "(", "resource", ",", "load_globals", ")", "return", "loader", ".", "build_metamodel", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
load_component
Load and return a model from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths.
bridgepoint/ooaofooa.py
def load_component(resource, name=None, load_globals=True): ''' Load and return a model from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths. ''' loader = _mk_loader(resource, load_globals) return loader.build_component()
def load_component(resource, name=None, load_globals=True): ''' Load and return a model from a *resource*. The resource may be either a filename, a path, or a list of filenames and/or paths. ''' loader = _mk_loader(resource, load_globals) return loader.build_component()
[ "Load", "and", "return", "a", "model", "from", "a", "*", "resource", "*", ".", "The", "resource", "may", "be", "either", "a", "filename", "a", "path", "or", "a", "list", "of", "filenames", "and", "/", "or", "paths", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L567-L573
[ "def", "load_component", "(", "resource", ",", "name", "=", "None", ",", "load_globals", "=", "True", ")", ":", "loader", "=", "_mk_loader", "(", "resource", ",", "load_globals", ")", "return", "loader", ".", "build_component", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
delete_globals
Remove global instances, e.g. the core data type integer.
bridgepoint/ooaofooa.py
def delete_globals(m, disconnect=False): ''' Remove global instances, e.g. the core data type integer. ''' filt = lambda sel: (247728914420827907967735776184937480192 <= sel.DT_ID <= 247728914420827907967735776184937480208) for s_dt in m.select_many('S_DT', filt): xtuml.delete(one(s_dt).PE_PE[8001](), disconnect) xtuml.delete(subtype(s_dt, 17), disconnect) xtuml.delete(s_dt, disconnect)
def delete_globals(m, disconnect=False): ''' Remove global instances, e.g. the core data type integer. ''' filt = lambda sel: (247728914420827907967735776184937480192 <= sel.DT_ID <= 247728914420827907967735776184937480208) for s_dt in m.select_many('S_DT', filt): xtuml.delete(one(s_dt).PE_PE[8001](), disconnect) xtuml.delete(subtype(s_dt, 17), disconnect) xtuml.delete(s_dt, disconnect)
[ "Remove", "global", "instances", "e", ".", "g", ".", "the", "core", "data", "type", "integer", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L576-L587
[ "def", "delete_globals", "(", "m", ",", "disconnect", "=", "False", ")", ":", "filt", "=", "lambda", "sel", ":", "(", "247728914420827907967735776184937480192", "<=", "sel", ".", "DT_ID", "<=", "247728914420827907967735776184937480208", ")", "for", "s_dt", "in", "m", ".", "select_many", "(", "'S_DT'", ",", "filt", ")", ":", "xtuml", ".", "delete", "(", "one", "(", "s_dt", ")", ".", "PE_PE", "[", "8001", "]", "(", ")", ",", "disconnect", ")", "xtuml", ".", "delete", "(", "subtype", "(", "s_dt", ",", "17", ")", ",", "disconnect", ")", "xtuml", ".", "delete", "(", "s_dt", ",", "disconnect", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.filename_input
Open and read input from a *path or filename*, and parse its content. If the filename is a directory, files that ends with .xtuml located somewhere in the directory or sub directories will be loaded as well.
bridgepoint/ooaofooa.py
def filename_input(self, path_or_filename): ''' Open and read input from a *path or filename*, and parse its content. If the filename is a directory, files that ends with .xtuml located somewhere in the directory or sub directories will be loaded as well. ''' if os.path.isdir(path_or_filename): for path, _, files in os.walk(path_or_filename): for name in files: if name.endswith('.xtuml'): xtuml.ModelLoader.filename_input(self, os.path.join(path, name)) else: xtuml.ModelLoader.filename_input(self, path_or_filename)
def filename_input(self, path_or_filename): ''' Open and read input from a *path or filename*, and parse its content. If the filename is a directory, files that ends with .xtuml located somewhere in the directory or sub directories will be loaded as well. ''' if os.path.isdir(path_or_filename): for path, _, files in os.walk(path_or_filename): for name in files: if name.endswith('.xtuml'): xtuml.ModelLoader.filename_input(self, os.path.join(path, name)) else: xtuml.ModelLoader.filename_input(self, path_or_filename)
[ "Open", "and", "read", "input", "from", "a", "*", "path", "or", "filename", "*", "and", "parse", "its", "content", ".", "If", "the", "filename", "is", "a", "directory", "files", "that", "ends", "with", ".", "xtuml", "located", "somewhere", "in", "the", "directory", "or", "sub", "directories", "will", "be", "loaded", "as", "well", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L506-L519
[ "def", "filename_input", "(", "self", ",", "path_or_filename", ")", ":", "if", "os", ".", "path", ".", "isdir", "(", "path_or_filename", ")", ":", "for", "path", ",", "_", ",", "files", "in", "os", ".", "walk", "(", "path_or_filename", ")", ":", "for", "name", "in", "files", ":", "if", "name", ".", "endswith", "(", "'.xtuml'", ")", ":", "xtuml", ".", "ModelLoader", ".", "filename_input", "(", "self", ",", "os", ".", "path", ".", "join", "(", "path", ",", "name", ")", ")", "else", ":", "xtuml", ".", "ModelLoader", ".", "filename_input", "(", "self", ",", "path_or_filename", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.build_component
Instantiate and build a component from ooaofooa named *name* as a pyxtuml model. Classes, associations, attributes and unique identifers, i.e. O_OBJ, R_REL, O_ATTR in ooaofooa, are defined in the resulting pyxtuml model. Optionally, control whether *derived attributes* shall be mapped into the resulting pyxtuml model as attributes or not. Futhermore, if no *name* is provided, the entire content of the ooaofooa model is instantiated into the pyxtuml model.
bridgepoint/ooaofooa.py
def build_component(self, name=None, derived_attributes=False): ''' Instantiate and build a component from ooaofooa named *name* as a pyxtuml model. Classes, associations, attributes and unique identifers, i.e. O_OBJ, R_REL, O_ATTR in ooaofooa, are defined in the resulting pyxtuml model. Optionally, control whether *derived attributes* shall be mapped into the resulting pyxtuml model as attributes or not. Futhermore, if no *name* is provided, the entire content of the ooaofooa model is instantiated into the pyxtuml model. ''' mm = self.build_metamodel() c_c = mm.select_any('C_C', where(Name=name)) if c_c: return mk_component(mm, c_c, derived_attributes) elif name: raise OoaOfOoaException('Unable to find the component %s' % name) else: return mk_component(mm, c_c, derived_attributes)
def build_component(self, name=None, derived_attributes=False): ''' Instantiate and build a component from ooaofooa named *name* as a pyxtuml model. Classes, associations, attributes and unique identifers, i.e. O_OBJ, R_REL, O_ATTR in ooaofooa, are defined in the resulting pyxtuml model. Optionally, control whether *derived attributes* shall be mapped into the resulting pyxtuml model as attributes or not. Futhermore, if no *name* is provided, the entire content of the ooaofooa model is instantiated into the pyxtuml model. ''' mm = self.build_metamodel() c_c = mm.select_any('C_C', where(Name=name)) if c_c: return mk_component(mm, c_c, derived_attributes) elif name: raise OoaOfOoaException('Unable to find the component %s' % name) else: return mk_component(mm, c_c, derived_attributes)
[ "Instantiate", "and", "build", "a", "component", "from", "ooaofooa", "named", "*", "name", "*", "as", "a", "pyxtuml", "model", ".", "Classes", "associations", "attributes", "and", "unique", "identifers", "i", ".", "e", ".", "O_OBJ", "R_REL", "O_ATTR", "in", "ooaofooa", "are", "defined", "in", "the", "resulting", "pyxtuml", "model", ".", "Optionally", "control", "whether", "*", "derived", "attributes", "*", "shall", "be", "mapped", "into", "the", "resulting", "pyxtuml", "model", "as", "attributes", "or", "not", ".", "Futhermore", "if", "no", "*", "name", "*", "is", "provided", "the", "entire", "content", "of", "the", "ooaofooa", "model", "is", "instantiated", "into", "the", "pyxtuml", "model", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L521-L541
[ "def", "build_component", "(", "self", ",", "name", "=", "None", ",", "derived_attributes", "=", "False", ")", ":", "mm", "=", "self", ".", "build_metamodel", "(", ")", "c_c", "=", "mm", ".", "select_any", "(", "'C_C'", ",", "where", "(", "Name", "=", "name", ")", ")", "if", "c_c", ":", "return", "mk_component", "(", "mm", ",", "c_c", ",", "derived_attributes", ")", "elif", "name", ":", "raise", "OoaOfOoaException", "(", "'Unable to find the component %s'", "%", "name", ")", "else", ":", "return", "mk_component", "(", "mm", ",", "c_c", ",", "derived_attributes", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
default_malformed_message_handler
The default malformed message handler for :class:`Worker`. It warns as a :exc:`MalformedMessage`.
zeronimo/core.py
def default_malformed_message_handler(worker, exc_info, message_parts): """The default malformed message handler for :class:`Worker`. It warns as a :exc:`MalformedMessage`. """ exc_type, exc, tb = exc_info exc_strs = traceback.format_exception_only(exc_type, exc) exc_str = exc_strs[0].strip() if len(exc_strs) > 1: exc_str += '...' warn('<%s> occurred by %r' % (exc_str, message_parts), MalformedMessage)
def default_malformed_message_handler(worker, exc_info, message_parts): """The default malformed message handler for :class:`Worker`. It warns as a :exc:`MalformedMessage`. """ exc_type, exc, tb = exc_info exc_strs = traceback.format_exception_only(exc_type, exc) exc_str = exc_strs[0].strip() if len(exc_strs) > 1: exc_str += '...' warn('<%s> occurred by %r' % (exc_str, message_parts), MalformedMessage)
[ "The", "default", "malformed", "message", "handler", "for", ":", "class", ":", "Worker", ".", "It", "warns", "as", "a", ":", "exc", ":", "MalformedMessage", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L133-L142
[ "def", "default_malformed_message_handler", "(", "worker", ",", "exc_info", ",", "message_parts", ")", ":", "exc_type", ",", "exc", ",", "tb", "=", "exc_info", "exc_strs", "=", "traceback", ".", "format_exception_only", "(", "exc_type", ",", "exc", ")", "exc_str", "=", "exc_strs", "[", "0", "]", ".", "strip", "(", ")", "if", "len", "(", "exc_strs", ")", ">", "1", ":", "exc_str", "+=", "'...'", "warn", "(", "'<%s> occurred by %r'", "%", "(", "exc_str", ",", "message_parts", ")", ",", "MalformedMessage", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Worker.work
Calls a function and send results to the collector. It supports all of function actions. A function could return, yield, raise any packable objects.
zeronimo/core.py
def work(self, socket, call, args, kwargs, topics=()): """Calls a function and send results to the collector. It supports all of function actions. A function could return, yield, raise any packable objects. """ task_id = uuid4_bytes() reply_socket, topics = self.replier(socket, topics, call.reply_to) if reply_socket: channel = (call.call_id, task_id, topics) else: channel = (None, None, None) f, rpc_spec = self.find_call_target(call) if rpc_spec.reject_if.__get__(self.app)(call, topics): reply_socket and self.reject(reply_socket, call.call_id, topics) return reply_socket and self.accept(reply_socket, channel) success = False with self.catch_exceptions(): try: val = self.call(call, args, kwargs, f, rpc_spec) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) success = True if not success: # catch_exceptions() hides exceptions. return if isinstance(val, Iterator): vals = val with self.catch_exceptions(): try: try: val = next(vals) except StopIteration: pass else: self.send_reply(reply_socket, YIELD, val, *channel) for val in vals: self.send_reply(reply_socket, YIELD, val, *channel) self.send_reply(reply_socket, BREAK, None, *channel) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) else: self.send_reply(reply_socket, RETURN, val, *channel)
def work(self, socket, call, args, kwargs, topics=()): """Calls a function and send results to the collector. It supports all of function actions. A function could return, yield, raise any packable objects. """ task_id = uuid4_bytes() reply_socket, topics = self.replier(socket, topics, call.reply_to) if reply_socket: channel = (call.call_id, task_id, topics) else: channel = (None, None, None) f, rpc_spec = self.find_call_target(call) if rpc_spec.reject_if.__get__(self.app)(call, topics): reply_socket and self.reject(reply_socket, call.call_id, topics) return reply_socket and self.accept(reply_socket, channel) success = False with self.catch_exceptions(): try: val = self.call(call, args, kwargs, f, rpc_spec) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) success = True if not success: # catch_exceptions() hides exceptions. return if isinstance(val, Iterator): vals = val with self.catch_exceptions(): try: try: val = next(vals) except StopIteration: pass else: self.send_reply(reply_socket, YIELD, val, *channel) for val in vals: self.send_reply(reply_socket, YIELD, val, *channel) self.send_reply(reply_socket, BREAK, None, *channel) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) else: self.send_reply(reply_socket, RETURN, val, *channel)
[ "Calls", "a", "function", "and", "send", "results", "to", "the", "collector", ".", "It", "supports", "all", "of", "function", "actions", ".", "A", "function", "could", "return", "yield", "raise", "any", "packable", "objects", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L268-L314
[ "def", "work", "(", "self", ",", "socket", ",", "call", ",", "args", ",", "kwargs", ",", "topics", "=", "(", ")", ")", ":", "task_id", "=", "uuid4_bytes", "(", ")", "reply_socket", ",", "topics", "=", "self", ".", "replier", "(", "socket", ",", "topics", ",", "call", ".", "reply_to", ")", "if", "reply_socket", ":", "channel", "=", "(", "call", ".", "call_id", ",", "task_id", ",", "topics", ")", "else", ":", "channel", "=", "(", "None", ",", "None", ",", "None", ")", "f", ",", "rpc_spec", "=", "self", ".", "find_call_target", "(", "call", ")", "if", "rpc_spec", ".", "reject_if", ".", "__get__", "(", "self", ".", "app", ")", "(", "call", ",", "topics", ")", ":", "reply_socket", "and", "self", ".", "reject", "(", "reply_socket", ",", "call", ".", "call_id", ",", "topics", ")", "return", "reply_socket", "and", "self", ".", "accept", "(", "reply_socket", ",", "channel", ")", "success", "=", "False", "with", "self", ".", "catch_exceptions", "(", ")", ":", "try", ":", "val", "=", "self", ".", "call", "(", "call", ",", "args", ",", "kwargs", ",", "f", ",", "rpc_spec", ")", "except", ":", "exc_info", "=", "sys", ".", "exc_info", "(", ")", "self", ".", "raise_", "(", "reply_socket", ",", "channel", ",", "exc_info", ")", "reraise", "(", "*", "exc_info", ")", "success", "=", "True", "if", "not", "success", ":", "# catch_exceptions() hides exceptions.", "return", "if", "isinstance", "(", "val", ",", "Iterator", ")", ":", "vals", "=", "val", "with", "self", ".", "catch_exceptions", "(", ")", ":", "try", ":", "try", ":", "val", "=", "next", "(", "vals", ")", "except", "StopIteration", ":", "pass", "else", ":", "self", ".", "send_reply", "(", "reply_socket", ",", "YIELD", ",", "val", ",", "*", "channel", ")", "for", "val", "in", "vals", ":", "self", ".", "send_reply", "(", "reply_socket", ",", "YIELD", ",", "val", ",", "*", "channel", ")", "self", ".", "send_reply", "(", "reply_socket", ",", "BREAK", ",", "None", ",", "*", "channel", ")", "except", ":", "exc_info", "=", "sys", ".", "exc_info", "(", ")", "self", ".", "raise_", "(", "reply_socket", ",", "channel", ",", "exc_info", ")", "reraise", "(", "*", "exc_info", ")", "else", ":", "self", ".", "send_reply", "(", "reply_socket", ",", "RETURN", ",", "val", ",", "*", "channel", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Worker.accept
Sends ACCEPT reply.
zeronimo/core.py
def accept(self, reply_socket, channel): """Sends ACCEPT reply.""" info = self.info or b'' self.send_raw(reply_socket, ACCEPT, info, *channel)
def accept(self, reply_socket, channel): """Sends ACCEPT reply.""" info = self.info or b'' self.send_raw(reply_socket, ACCEPT, info, *channel)
[ "Sends", "ACCEPT", "reply", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L331-L334
[ "def", "accept", "(", "self", ",", "reply_socket", ",", "channel", ")", ":", "info", "=", "self", ".", "info", "or", "b''", "self", ".", "send_raw", "(", "reply_socket", ",", "ACCEPT", ",", "info", ",", "*", "channel", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Worker.reject
Sends REJECT reply.
zeronimo/core.py
def reject(self, reply_socket, call_id, topics=()): """Sends REJECT reply.""" info = self.info or b'' self.send_raw(reply_socket, REJECT, info, call_id, b'', topics)
def reject(self, reply_socket, call_id, topics=()): """Sends REJECT reply.""" info = self.info or b'' self.send_raw(reply_socket, REJECT, info, call_id, b'', topics)
[ "Sends", "REJECT", "reply", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L336-L339
[ "def", "reject", "(", "self", ",", "reply_socket", ",", "call_id", ",", "topics", "=", "(", ")", ")", ":", "info", "=", "self", ".", "info", "or", "b''", "self", ".", "send_raw", "(", "reply_socket", ",", "REJECT", ",", "info", ",", "call_id", ",", "b''", ",", "topics", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Worker.raise_
Sends RAISE reply.
zeronimo/core.py
def raise_(self, reply_socket, channel, exc_info=None): """Sends RAISE reply.""" if not reply_socket: return if exc_info is None: exc_info = sys.exc_info() exc_type, exc, tb = exc_info while tb.tb_next is not None: tb = tb.tb_next if issubclass(exc_type, RemoteException): exc_type = exc_type.exc_type filename, lineno = tb.tb_frame.f_code.co_filename, tb.tb_lineno val = (exc_type, str(exc), filename, lineno) try: state = exc.__getstate__() except AttributeError: pass else: val += (state,) self.send_reply(reply_socket, RAISE, val, *channel)
def raise_(self, reply_socket, channel, exc_info=None): """Sends RAISE reply.""" if not reply_socket: return if exc_info is None: exc_info = sys.exc_info() exc_type, exc, tb = exc_info while tb.tb_next is not None: tb = tb.tb_next if issubclass(exc_type, RemoteException): exc_type = exc_type.exc_type filename, lineno = tb.tb_frame.f_code.co_filename, tb.tb_lineno val = (exc_type, str(exc), filename, lineno) try: state = exc.__getstate__() except AttributeError: pass else: val += (state,) self.send_reply(reply_socket, RAISE, val, *channel)
[ "Sends", "RAISE", "reply", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L341-L360
[ "def", "raise_", "(", "self", ",", "reply_socket", ",", "channel", ",", "exc_info", "=", "None", ")", ":", "if", "not", "reply_socket", ":", "return", "if", "exc_info", "is", "None", ":", "exc_info", "=", "sys", ".", "exc_info", "(", ")", "exc_type", ",", "exc", ",", "tb", "=", "exc_info", "while", "tb", ".", "tb_next", "is", "not", "None", ":", "tb", "=", "tb", ".", "tb_next", "if", "issubclass", "(", "exc_type", ",", "RemoteException", ")", ":", "exc_type", "=", "exc_type", ".", "exc_type", "filename", ",", "lineno", "=", "tb", ".", "tb_frame", ".", "f_code", ".", "co_filename", ",", "tb", ".", "tb_lineno", "val", "=", "(", "exc_type", ",", "str", "(", "exc", ")", ",", "filename", ",", "lineno", ")", "try", ":", "state", "=", "exc", ".", "__getstate__", "(", ")", "except", "AttributeError", ":", "pass", "else", ":", "val", "+=", "(", "state", ",", ")", "self", ".", "send_reply", "(", "reply_socket", ",", "RAISE", ",", "val", ",", "*", "channel", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
_Caller._call_wait
Allocates a call id and emit.
zeronimo/core.py
def _call_wait(self, hints, name, args, kwargs, topics=(), raw=False, limit=None, retry=False, max_retries=None): """Allocates a call id and emit.""" col = self.collector if not col.is_running(): col.start() call_id = uuid4_bytes() reply_to = (DUPLEX if self.socket is col.socket else col.topic) # Normal tuple is faster than namedtuple. header = self._make_header(name, call_id, reply_to, hints) payload = self._pack(args, kwargs, raw) # Use short names. def send_call(): try: safe(send, self.socket, header, payload, topics, zmq.NOBLOCK) except zmq.Again: raise Undelivered('emission was not delivered') col.prepare(call_id, self, name, args, kwargs) send_call() return col.establish(call_id, self.timeout, limit, send_call if retry else None, max_retries=max_retries)
def _call_wait(self, hints, name, args, kwargs, topics=(), raw=False, limit=None, retry=False, max_retries=None): """Allocates a call id and emit.""" col = self.collector if not col.is_running(): col.start() call_id = uuid4_bytes() reply_to = (DUPLEX if self.socket is col.socket else col.topic) # Normal tuple is faster than namedtuple. header = self._make_header(name, call_id, reply_to, hints) payload = self._pack(args, kwargs, raw) # Use short names. def send_call(): try: safe(send, self.socket, header, payload, topics, zmq.NOBLOCK) except zmq.Again: raise Undelivered('emission was not delivered') col.prepare(call_id, self, name, args, kwargs) send_call() return col.establish(call_id, self.timeout, limit, send_call if retry else None, max_retries=max_retries)
[ "Allocates", "a", "call", "id", "and", "emit", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L454-L475
[ "def", "_call_wait", "(", "self", ",", "hints", ",", "name", ",", "args", ",", "kwargs", ",", "topics", "=", "(", ")", ",", "raw", "=", "False", ",", "limit", "=", "None", ",", "retry", "=", "False", ",", "max_retries", "=", "None", ")", ":", "col", "=", "self", ".", "collector", "if", "not", "col", ".", "is_running", "(", ")", ":", "col", ".", "start", "(", ")", "call_id", "=", "uuid4_bytes", "(", ")", "reply_to", "=", "(", "DUPLEX", "if", "self", ".", "socket", "is", "col", ".", "socket", "else", "col", ".", "topic", ")", "# Normal tuple is faster than namedtuple.", "header", "=", "self", ".", "_make_header", "(", "name", ",", "call_id", ",", "reply_to", ",", "hints", ")", "payload", "=", "self", ".", "_pack", "(", "args", ",", "kwargs", ",", "raw", ")", "# Use short names.", "def", "send_call", "(", ")", ":", "try", ":", "safe", "(", "send", ",", "self", ".", "socket", ",", "header", ",", "payload", ",", "topics", ",", "zmq", ".", "NOBLOCK", ")", "except", "zmq", ".", "Again", ":", "raise", "Undelivered", "(", "'emission was not delivered'", ")", "col", ".", "prepare", "(", "call_id", ",", "self", ",", "name", ",", "args", ",", "kwargs", ")", "send_call", "(", ")", "return", "col", ".", "establish", "(", "call_id", ",", "self", ".", "timeout", ",", "limit", ",", "send_call", "if", "retry", "else", "None", ",", "max_retries", "=", "max_retries", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Collector.establish
Waits for the call is accepted by workers and starts to collect the results.
zeronimo/core.py
def establish(self, call_id, timeout, limit=None, retry=None, max_retries=None): """Waits for the call is accepted by workers and starts to collect the results. """ rejected = 0 retried = 0 results = [] result_queue = self.result_queues[call_id] try: with Timeout(timeout, False): while True: result = result_queue.get() if result is None: rejected += 1 if retry is not None: if retried == max_retries: break retry() retried += 1 continue results.append(result) if len(results) == limit: break finally: del result_queue self.remove_result_queue(call_id) if not results: if rejected: raise Rejected('%d workers rejected' % rejected if rejected != 1 else 'A worker rejected') else: raise WorkerNotFound('failed to find worker') return results
def establish(self, call_id, timeout, limit=None, retry=None, max_retries=None): """Waits for the call is accepted by workers and starts to collect the results. """ rejected = 0 retried = 0 results = [] result_queue = self.result_queues[call_id] try: with Timeout(timeout, False): while True: result = result_queue.get() if result is None: rejected += 1 if retry is not None: if retried == max_retries: break retry() retried += 1 continue results.append(result) if len(results) == limit: break finally: del result_queue self.remove_result_queue(call_id) if not results: if rejected: raise Rejected('%d workers rejected' % rejected if rejected != 1 else 'A worker rejected') else: raise WorkerNotFound('failed to find worker') return results
[ "Waits", "for", "the", "call", "is", "accepted", "by", "workers", "and", "starts", "to", "collect", "the", "results", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L607-L641
[ "def", "establish", "(", "self", ",", "call_id", ",", "timeout", ",", "limit", "=", "None", ",", "retry", "=", "None", ",", "max_retries", "=", "None", ")", ":", "rejected", "=", "0", "retried", "=", "0", "results", "=", "[", "]", "result_queue", "=", "self", ".", "result_queues", "[", "call_id", "]", "try", ":", "with", "Timeout", "(", "timeout", ",", "False", ")", ":", "while", "True", ":", "result", "=", "result_queue", ".", "get", "(", ")", "if", "result", "is", "None", ":", "rejected", "+=", "1", "if", "retry", "is", "not", "None", ":", "if", "retried", "==", "max_retries", ":", "break", "retry", "(", ")", "retried", "+=", "1", "continue", "results", ".", "append", "(", "result", ")", "if", "len", "(", "results", ")", "==", "limit", ":", "break", "finally", ":", "del", "result_queue", "self", ".", "remove_result_queue", "(", "call_id", ")", "if", "not", "results", ":", "if", "rejected", ":", "raise", "Rejected", "(", "'%d workers rejected'", "%", "rejected", "if", "rejected", "!=", "1", "else", "'A worker rejected'", ")", "else", ":", "raise", "WorkerNotFound", "(", "'failed to find worker'", ")", "return", "results" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
Collector.dispatch_reply
Dispatches the reply to the proper queue.
zeronimo/core.py
def dispatch_reply(self, reply, value): """Dispatches the reply to the proper queue.""" method = reply.method call_id = reply.call_id task_id = reply.task_id if method & ACK: try: result_queue = self.result_queues[call_id] except KeyError: raise KeyError('already established or unprepared call') if method == ACCEPT: worker_info = value result = RemoteResult(self, call_id, task_id, worker_info) self.results[call_id][task_id] = result result_queue.put_nowait(result) elif method == REJECT: result_queue.put_nowait(None) else: result = self.results[call_id][task_id] result.set_reply(reply.method, value)
def dispatch_reply(self, reply, value): """Dispatches the reply to the proper queue.""" method = reply.method call_id = reply.call_id task_id = reply.task_id if method & ACK: try: result_queue = self.result_queues[call_id] except KeyError: raise KeyError('already established or unprepared call') if method == ACCEPT: worker_info = value result = RemoteResult(self, call_id, task_id, worker_info) self.results[call_id][task_id] = result result_queue.put_nowait(result) elif method == REJECT: result_queue.put_nowait(None) else: result = self.results[call_id][task_id] result.set_reply(reply.method, value)
[ "Dispatches", "the", "reply", "to", "the", "proper", "queue", "." ]
sublee/zeronimo
python
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/core.py#L675-L694
[ "def", "dispatch_reply", "(", "self", ",", "reply", ",", "value", ")", ":", "method", "=", "reply", ".", "method", "call_id", "=", "reply", ".", "call_id", "task_id", "=", "reply", ".", "task_id", "if", "method", "&", "ACK", ":", "try", ":", "result_queue", "=", "self", ".", "result_queues", "[", "call_id", "]", "except", "KeyError", ":", "raise", "KeyError", "(", "'already established or unprepared call'", ")", "if", "method", "==", "ACCEPT", ":", "worker_info", "=", "value", "result", "=", "RemoteResult", "(", "self", ",", "call_id", ",", "task_id", ",", "worker_info", ")", "self", ".", "results", "[", "call_id", "]", "[", "task_id", "]", "=", "result", "result_queue", ".", "put_nowait", "(", "result", ")", "elif", "method", "==", "REJECT", ":", "result_queue", ".", "put_nowait", "(", "None", ")", "else", ":", "result", "=", "self", ".", "results", "[", "call_id", "]", "[", "task_id", "]", "result", ".", "set_reply", "(", "reply", ".", "method", ",", "value", ")" ]
b216638232932718d2cbc5eabd870c8f5b5e83fb
test
guess_type_name
Guess the type name of a serialized value.
xtuml/load.py
def guess_type_name(value): ''' Guess the type name of a serialized value. ''' value = str(value) if value.upper() in ['TRUE', 'FALSE']: return 'BOOLEAN' elif re.match(r'(-)?(\d+)(\.\d+)', value): return 'REAL' elif re.match(r'(-)?(\d+)', value): return 'INTEGER' elif re.match(r'\'((\'\')|[^\'])*\'', value): return 'STRING' elif re.match(r'\"([^\\\n]|(\\.))*?\"', value): return 'UNIQUE_ID'
def guess_type_name(value): ''' Guess the type name of a serialized value. ''' value = str(value) if value.upper() in ['TRUE', 'FALSE']: return 'BOOLEAN' elif re.match(r'(-)?(\d+)(\.\d+)', value): return 'REAL' elif re.match(r'(-)?(\d+)', value): return 'INTEGER' elif re.match(r'\'((\'\')|[^\'])*\'', value): return 'STRING' elif re.match(r'\"([^\\\n]|(\\.))*?\"', value): return 'UNIQUE_ID'
[ "Guess", "the", "type", "name", "of", "a", "serialized", "value", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L37-L56
[ "def", "guess_type_name", "(", "value", ")", ":", "value", "=", "str", "(", "value", ")", "if", "value", ".", "upper", "(", ")", "in", "[", "'TRUE'", ",", "'FALSE'", "]", ":", "return", "'BOOLEAN'", "elif", "re", ".", "match", "(", "r'(-)?(\\d+)(\\.\\d+)'", ",", "value", ")", ":", "return", "'REAL'", "elif", "re", ".", "match", "(", "r'(-)?(\\d+)'", ",", "value", ")", ":", "return", "'INTEGER'", "elif", "re", ".", "match", "(", "r'\\'((\\'\\')|[^\\'])*\\''", ",", "value", ")", ":", "return", "'STRING'", "elif", "re", ".", "match", "(", "r'\\\"([^\\\\\\n]|(\\\\.))*?\\\"'", ",", "value", ")", ":", "return", "'UNIQUE_ID'" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
deserialize_value
Deserialize a value of some type
xtuml/load.py
def deserialize_value(ty, value): ''' Deserialize a value of some type ''' uty = ty.upper() if uty == 'BOOLEAN': if value.isdigit(): return bool(int(value)) elif value.upper() == 'FALSE': return False elif value.upper() == 'TRUE': return True else: return None elif uty == 'INTEGER': if '"' in value: return uuid.UUID(value[1:-1]).int else: return int(value) elif uty == 'REAL': return float(value) elif uty == 'STRING': return value[1:-1].replace("''", "'") elif uty == 'UNIQUE_ID': if '"' in value: return uuid.UUID(value[1:-1]).int else: return int(value)
def deserialize_value(ty, value): ''' Deserialize a value of some type ''' uty = ty.upper() if uty == 'BOOLEAN': if value.isdigit(): return bool(int(value)) elif value.upper() == 'FALSE': return False elif value.upper() == 'TRUE': return True else: return None elif uty == 'INTEGER': if '"' in value: return uuid.UUID(value[1:-1]).int else: return int(value) elif uty == 'REAL': return float(value) elif uty == 'STRING': return value[1:-1].replace("''", "'") elif uty == 'UNIQUE_ID': if '"' in value: return uuid.UUID(value[1:-1]).int else: return int(value)
[ "Deserialize", "a", "value", "of", "some", "type" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L59-L91
[ "def", "deserialize_value", "(", "ty", ",", "value", ")", ":", "uty", "=", "ty", ".", "upper", "(", ")", "if", "uty", "==", "'BOOLEAN'", ":", "if", "value", ".", "isdigit", "(", ")", ":", "return", "bool", "(", "int", "(", "value", ")", ")", "elif", "value", ".", "upper", "(", ")", "==", "'FALSE'", ":", "return", "False", "elif", "value", ".", "upper", "(", ")", "==", "'TRUE'", ":", "return", "True", "else", ":", "return", "None", "elif", "uty", "==", "'INTEGER'", ":", "if", "'\"'", "in", "value", ":", "return", "uuid", ".", "UUID", "(", "value", "[", "1", ":", "-", "1", "]", ")", ".", "int", "else", ":", "return", "int", "(", "value", ")", "elif", "uty", "==", "'REAL'", ":", "return", "float", "(", "value", ")", "elif", "uty", "==", "'STRING'", ":", "return", "value", "[", "1", ":", "-", "1", "]", ".", "replace", "(", "\"''\"", ",", "\"'\"", ")", "elif", "uty", "==", "'UNIQUE_ID'", ":", "if", "'\"'", "in", "value", ":", "return", "uuid", ".", "UUID", "(", "value", "[", "1", ":", "-", "1", "]", ")", ".", "int", "else", ":", "return", "int", "(", "value", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
load_metamodel
Load and return a metamodel from a *resource*. The *resource* may be either a filename, or a list of filenames. Usage example: >>> metamodel = xtuml.load_metamodel(['schema.sql', 'data.sql'])
xtuml/load.py
def load_metamodel(resource): ''' Load and return a metamodel from a *resource*. The *resource* may be either a filename, or a list of filenames. Usage example: >>> metamodel = xtuml.load_metamodel(['schema.sql', 'data.sql']) ''' if isinstance(resource, str): resource = [resource] loader = ModelLoader() for filename in resource: loader.filename_input(filename) return loader.build_metamodel()
def load_metamodel(resource): ''' Load and return a metamodel from a *resource*. The *resource* may be either a filename, or a list of filenames. Usage example: >>> metamodel = xtuml.load_metamodel(['schema.sql', 'data.sql']) ''' if isinstance(resource, str): resource = [resource] loader = ModelLoader() for filename in resource: loader.filename_input(filename) return loader.build_metamodel()
[ "Load", "and", "return", "a", "metamodel", "from", "a", "*", "resource", "*", ".", "The", "*", "resource", "*", "may", "be", "either", "a", "filename", "or", "a", "list", "of", "filenames", ".", "Usage", "example", ":", ">>>", "metamodel", "=", "xtuml", ".", "load_metamodel", "(", "[", "schema", ".", "sql", "data", ".", "sql", "]", ")" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L696-L712
[ "def", "load_metamodel", "(", "resource", ")", ":", "if", "isinstance", "(", "resource", ",", "str", ")", ":", "resource", "=", "[", "resource", "]", "loader", "=", "ModelLoader", "(", ")", "for", "filename", "in", "resource", ":", "loader", ".", "filename_input", "(", "filename", ")", "return", "loader", ".", "build_metamodel", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.input
Parse *data* directly from a string. The *name* is used when reporting positional information if the parser encounter syntax errors.
xtuml/load.py
def input(self, data, name='<string>'): ''' Parse *data* directly from a string. The *name* is used when reporting positional information if the parser encounter syntax errors. ''' lexer = lex.lex(debuglog=logger, errorlog=logger, optimize=1, module=self, outputdir=os.path.dirname(__file__), lextab="xtuml.__xtuml_lextab") lexer.filename = name logger.debug('parsing %s' % name) s = self.parser.parse(lexer=lexer, input=data, tracking=1) self.statements.extend(s)
def input(self, data, name='<string>'): ''' Parse *data* directly from a string. The *name* is used when reporting positional information if the parser encounter syntax errors. ''' lexer = lex.lex(debuglog=logger, errorlog=logger, optimize=1, module=self, outputdir=os.path.dirname(__file__), lextab="xtuml.__xtuml_lextab") lexer.filename = name logger.debug('parsing %s' % name) s = self.parser.parse(lexer=lexer, input=data, tracking=1) self.statements.extend(s)
[ "Parse", "*", "data", "*", "directly", "from", "a", "string", ".", "The", "*", "name", "*", "is", "used", "when", "reporting", "positional", "information", "if", "the", "parser", "encounter", "syntax", "errors", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L214-L228
[ "def", "input", "(", "self", ",", "data", ",", "name", "=", "'<string>'", ")", ":", "lexer", "=", "lex", ".", "lex", "(", "debuglog", "=", "logger", ",", "errorlog", "=", "logger", ",", "optimize", "=", "1", ",", "module", "=", "self", ",", "outputdir", "=", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ",", "lextab", "=", "\"xtuml.__xtuml_lextab\"", ")", "lexer", ".", "filename", "=", "name", "logger", ".", "debug", "(", "'parsing %s'", "%", "name", ")", "s", "=", "self", ".", "parser", ".", "parse", "(", "lexer", "=", "lexer", ",", "input", "=", "data", ",", "tracking", "=", "1", ")", "self", ".", "statements", ".", "extend", "(", "s", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.file_input
Read and parse data from a *file object*, i.e. the type of object returned by the builtin python function *open()*.
xtuml/load.py
def file_input(self, file_object): ''' Read and parse data from a *file object*, i.e. the type of object returned by the builtin python function *open()*. ''' return self.input(file_object.read(), name=file_object.name)
def file_input(self, file_object): ''' Read and parse data from a *file object*, i.e. the type of object returned by the builtin python function *open()*. ''' return self.input(file_object.read(), name=file_object.name)
[ "Read", "and", "parse", "data", "from", "a", "*", "file", "object", "*", "i", ".", "e", ".", "the", "type", "of", "object", "returned", "by", "the", "builtin", "python", "function", "*", "open", "()", "*", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L237-L242
[ "def", "file_input", "(", "self", ",", "file_object", ")", ":", "return", "self", ".", "input", "(", "file_object", ".", "read", "(", ")", ",", "name", "=", "file_object", ".", "name", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate_classes
Populate a *metamodel* with classes previously encountered from input.
xtuml/load.py
def populate_classes(self, metamodel): ''' Populate a *metamodel* with classes previously encountered from input. ''' for stmt in self.statements: if isinstance(stmt, CreateClassStmt): metamodel.define_class(stmt.kind, stmt.attributes)
def populate_classes(self, metamodel): ''' Populate a *metamodel* with classes previously encountered from input. ''' for stmt in self.statements: if isinstance(stmt, CreateClassStmt): metamodel.define_class(stmt.kind, stmt.attributes)
[ "Populate", "a", "*", "metamodel", "*", "with", "classes", "previously", "encountered", "from", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L244-L250
[ "def", "populate_classes", "(", "self", ",", "metamodel", ")", ":", "for", "stmt", "in", "self", ".", "statements", ":", "if", "isinstance", "(", "stmt", ",", "CreateClassStmt", ")", ":", "metamodel", ".", "define_class", "(", "stmt", ".", "kind", ",", "stmt", ".", "attributes", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate_associations
Populate a *metamodel* with associations previously encountered from input.
xtuml/load.py
def populate_associations(self, metamodel): ''' Populate a *metamodel* with associations previously encountered from input. ''' for stmt in self.statements: if not isinstance(stmt, CreateAssociationStmt): continue ass = metamodel.define_association(stmt.rel_id, stmt.source_kind, stmt.source_keys, 'M' in stmt.source_cardinality, 'C' in stmt.source_cardinality, stmt.source_phrase, stmt.target_kind, stmt.target_keys, 'M' in stmt.target_cardinality, 'C' in stmt.target_cardinality, stmt.target_phrase) ass.formalize()
def populate_associations(self, metamodel): ''' Populate a *metamodel* with associations previously encountered from input. ''' for stmt in self.statements: if not isinstance(stmt, CreateAssociationStmt): continue ass = metamodel.define_association(stmt.rel_id, stmt.source_kind, stmt.source_keys, 'M' in stmt.source_cardinality, 'C' in stmt.source_cardinality, stmt.source_phrase, stmt.target_kind, stmt.target_keys, 'M' in stmt.target_cardinality, 'C' in stmt.target_cardinality, stmt.target_phrase) ass.formalize()
[ "Populate", "a", "*", "metamodel", "*", "with", "associations", "previously", "encountered", "from", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L252-L272
[ "def", "populate_associations", "(", "self", ",", "metamodel", ")", ":", "for", "stmt", "in", "self", ".", "statements", ":", "if", "not", "isinstance", "(", "stmt", ",", "CreateAssociationStmt", ")", ":", "continue", "ass", "=", "metamodel", ".", "define_association", "(", "stmt", ".", "rel_id", ",", "stmt", ".", "source_kind", ",", "stmt", ".", "source_keys", ",", "'M'", "in", "stmt", ".", "source_cardinality", ",", "'C'", "in", "stmt", ".", "source_cardinality", ",", "stmt", ".", "source_phrase", ",", "stmt", ".", "target_kind", ",", "stmt", ".", "target_keys", ",", "'M'", "in", "stmt", ".", "target_cardinality", ",", "'C'", "in", "stmt", ".", "target_cardinality", ",", "stmt", ".", "target_phrase", ")", "ass", ".", "formalize", "(", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate_unique_identifiers
Populate a *metamodel* with class unique identifiers previously encountered from input.
xtuml/load.py
def populate_unique_identifiers(self, metamodel): ''' Populate a *metamodel* with class unique identifiers previously encountered from input. ''' for stmt in self.statements: if isinstance(stmt, CreateUniqueStmt): metamodel.define_unique_identifier(stmt.kind, stmt.name, *stmt.attributes)
def populate_unique_identifiers(self, metamodel): ''' Populate a *metamodel* with class unique identifiers previously encountered from input. ''' for stmt in self.statements: if isinstance(stmt, CreateUniqueStmt): metamodel.define_unique_identifier(stmt.kind, stmt.name, *stmt.attributes)
[ "Populate", "a", "*", "metamodel", "*", "with", "class", "unique", "identifiers", "previously", "encountered", "from", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L274-L282
[ "def", "populate_unique_identifiers", "(", "self", ",", "metamodel", ")", ":", "for", "stmt", "in", "self", ".", "statements", ":", "if", "isinstance", "(", "stmt", ",", "CreateUniqueStmt", ")", ":", "metamodel", ".", "define_unique_identifier", "(", "stmt", ".", "kind", ",", "stmt", ".", "name", ",", "*", "stmt", ".", "attributes", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader._populate_matching_class
Populate a *metamodel* with a class that matches the given *insert statement*.
xtuml/load.py
def _populate_matching_class(metamodel, kind, names, values): ''' Populate a *metamodel* with a class that matches the given *insert statement*. ''' attributes = list() for name, value in zip(names, values): ty = guess_type_name(value) attr = (name, ty) attributes.append(attr) return metamodel.define_class(kind, attributes)
def _populate_matching_class(metamodel, kind, names, values): ''' Populate a *metamodel* with a class that matches the given *insert statement*. ''' attributes = list() for name, value in zip(names, values): ty = guess_type_name(value) attr = (name, ty) attributes.append(attr) return metamodel.define_class(kind, attributes)
[ "Populate", "a", "*", "metamodel", "*", "with", "a", "class", "that", "matches", "the", "given", "*", "insert", "statement", "*", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L285-L296
[ "def", "_populate_matching_class", "(", "metamodel", ",", "kind", ",", "names", ",", "values", ")", ":", "attributes", "=", "list", "(", ")", "for", "name", ",", "value", "in", "zip", "(", "names", ",", "values", ")", ":", "ty", "=", "guess_type_name", "(", "value", ")", "attr", "=", "(", "name", ",", "ty", ")", "attributes", ".", "append", "(", "attr", ")", "return", "metamodel", ".", "define_class", "(", "kind", ",", "attributes", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader._populate_instance_with_positional_arguments
Populate a *metamodel* with an instance previously encountered from input that was defined using positional arguments.
xtuml/load.py
def _populate_instance_with_positional_arguments(metamodel, stmt): ''' Populate a *metamodel* with an instance previously encountered from input that was defined using positional arguments. ''' if stmt.kind.upper() not in metamodel.metaclasses: names = ['_%s' % idx for idx in range(len(stmt.values))] ModelLoader._populate_matching_class(metamodel, stmt.kind, names, stmt.values) metaclass = metamodel.find_metaclass(stmt.kind) if len(metaclass.attributes) != len(stmt.values): logger.warn('%s:%d:schema mismatch' % (stmt.filename, stmt.lineno)) inst = metamodel.new(stmt.kind) for attr, value in zip(metaclass.attributes, stmt.values): name, ty = attr py_value = deserialize_value(ty, value) if py_value is None: raise ParsingException("%s:%d:unable to deserialize "\ "%s to a %s" % (stmt.filename, stmt.lineno, value, ty)) inst.__dict__[name] = py_value return inst
def _populate_instance_with_positional_arguments(metamodel, stmt): ''' Populate a *metamodel* with an instance previously encountered from input that was defined using positional arguments. ''' if stmt.kind.upper() not in metamodel.metaclasses: names = ['_%s' % idx for idx in range(len(stmt.values))] ModelLoader._populate_matching_class(metamodel, stmt.kind, names, stmt.values) metaclass = metamodel.find_metaclass(stmt.kind) if len(metaclass.attributes) != len(stmt.values): logger.warn('%s:%d:schema mismatch' % (stmt.filename, stmt.lineno)) inst = metamodel.new(stmt.kind) for attr, value in zip(metaclass.attributes, stmt.values): name, ty = attr py_value = deserialize_value(ty, value) if py_value is None: raise ParsingException("%s:%d:unable to deserialize "\ "%s to a %s" % (stmt.filename, stmt.lineno, value, ty)) inst.__dict__[name] = py_value return inst
[ "Populate", "a", "*", "metamodel", "*", "with", "an", "instance", "previously", "encountered", "from", "input", "that", "was", "defined", "using", "positional", "arguments", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L299-L326
[ "def", "_populate_instance_with_positional_arguments", "(", "metamodel", ",", "stmt", ")", ":", "if", "stmt", ".", "kind", ".", "upper", "(", ")", "not", "in", "metamodel", ".", "metaclasses", ":", "names", "=", "[", "'_%s'", "%", "idx", "for", "idx", "in", "range", "(", "len", "(", "stmt", ".", "values", ")", ")", "]", "ModelLoader", ".", "_populate_matching_class", "(", "metamodel", ",", "stmt", ".", "kind", ",", "names", ",", "stmt", ".", "values", ")", "metaclass", "=", "metamodel", ".", "find_metaclass", "(", "stmt", ".", "kind", ")", "if", "len", "(", "metaclass", ".", "attributes", ")", "!=", "len", "(", "stmt", ".", "values", ")", ":", "logger", ".", "warn", "(", "'%s:%d:schema mismatch'", "%", "(", "stmt", ".", "filename", ",", "stmt", ".", "lineno", ")", ")", "inst", "=", "metamodel", ".", "new", "(", "stmt", ".", "kind", ")", "for", "attr", ",", "value", "in", "zip", "(", "metaclass", ".", "attributes", ",", "stmt", ".", "values", ")", ":", "name", ",", "ty", "=", "attr", "py_value", "=", "deserialize_value", "(", "ty", ",", "value", ")", "if", "py_value", "is", "None", ":", "raise", "ParsingException", "(", "\"%s:%d:unable to deserialize \"", "\"%s to a %s\"", "%", "(", "stmt", ".", "filename", ",", "stmt", ".", "lineno", ",", "value", ",", "ty", ")", ")", "inst", ".", "__dict__", "[", "name", "]", "=", "py_value", "return", "inst" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader._populate_instance_with_named_arguments
Populate a *metamodel* with an instance previously encountered from input that was defined using named arguments.
xtuml/load.py
def _populate_instance_with_named_arguments(metamodel, stmt): ''' Populate a *metamodel* with an instance previously encountered from input that was defined using named arguments. ''' if stmt.kind.upper() not in metamodel.metaclasses: ModelLoader._populate_matching_class(metamodel, stmt.kind, stmt.names, stmt.values) metaclass = metamodel.find_metaclass(stmt.kind) schema_unames = [name.upper() for name in metaclass.attribute_names] inst_unames = [name.upper() for name in stmt.names] if set(inst_unames) - set(schema_unames): logger.warn('%s:%d:schema mismatch' % (stmt.filename, stmt.lineno)) inst = metamodel.new(stmt.kind) for name, ty in metaclass.attributes: uname = name.upper() if uname in inst_unames: idx = inst_unames.index(uname) value = deserialize_value(ty, stmt.values[idx]) if value is None: raise ParsingException("%s:%d:unable to deserialize "\ "%s to a %s" % (stmt.filename, stmt.lineno, value, ty)) else: value = None inst.__dict__[name] = value return inst
def _populate_instance_with_named_arguments(metamodel, stmt): ''' Populate a *metamodel* with an instance previously encountered from input that was defined using named arguments. ''' if stmt.kind.upper() not in metamodel.metaclasses: ModelLoader._populate_matching_class(metamodel, stmt.kind, stmt.names, stmt.values) metaclass = metamodel.find_metaclass(stmt.kind) schema_unames = [name.upper() for name in metaclass.attribute_names] inst_unames = [name.upper() for name in stmt.names] if set(inst_unames) - set(schema_unames): logger.warn('%s:%d:schema mismatch' % (stmt.filename, stmt.lineno)) inst = metamodel.new(stmt.kind) for name, ty in metaclass.attributes: uname = name.upper() if uname in inst_unames: idx = inst_unames.index(uname) value = deserialize_value(ty, stmt.values[idx]) if value is None: raise ParsingException("%s:%d:unable to deserialize "\ "%s to a %s" % (stmt.filename, stmt.lineno, value, ty)) else: value = None inst.__dict__[name] = value return inst
[ "Populate", "a", "*", "metamodel", "*", "with", "an", "instance", "previously", "encountered", "from", "input", "that", "was", "defined", "using", "named", "arguments", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L329-L363
[ "def", "_populate_instance_with_named_arguments", "(", "metamodel", ",", "stmt", ")", ":", "if", "stmt", ".", "kind", ".", "upper", "(", ")", "not", "in", "metamodel", ".", "metaclasses", ":", "ModelLoader", ".", "_populate_matching_class", "(", "metamodel", ",", "stmt", ".", "kind", ",", "stmt", ".", "names", ",", "stmt", ".", "values", ")", "metaclass", "=", "metamodel", ".", "find_metaclass", "(", "stmt", ".", "kind", ")", "schema_unames", "=", "[", "name", ".", "upper", "(", ")", "for", "name", "in", "metaclass", ".", "attribute_names", "]", "inst_unames", "=", "[", "name", ".", "upper", "(", ")", "for", "name", "in", "stmt", ".", "names", "]", "if", "set", "(", "inst_unames", ")", "-", "set", "(", "schema_unames", ")", ":", "logger", ".", "warn", "(", "'%s:%d:schema mismatch'", "%", "(", "stmt", ".", "filename", ",", "stmt", ".", "lineno", ")", ")", "inst", "=", "metamodel", ".", "new", "(", "stmt", ".", "kind", ")", "for", "name", ",", "ty", "in", "metaclass", ".", "attributes", ":", "uname", "=", "name", ".", "upper", "(", ")", "if", "uname", "in", "inst_unames", ":", "idx", "=", "inst_unames", ".", "index", "(", "uname", ")", "value", "=", "deserialize_value", "(", "ty", ",", "stmt", ".", "values", "[", "idx", "]", ")", "if", "value", "is", "None", ":", "raise", "ParsingException", "(", "\"%s:%d:unable to deserialize \"", "\"%s to a %s\"", "%", "(", "stmt", ".", "filename", ",", "stmt", ".", "lineno", ",", "value", ",", "ty", ")", ")", "else", ":", "value", "=", "None", "inst", ".", "__dict__", "[", "name", "]", "=", "value", "return", "inst" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate_instances
Populate a *metamodel* with instances previously encountered from input.
xtuml/load.py
def populate_instances(self, metamodel): ''' Populate a *metamodel* with instances previously encountered from input. ''' for stmt in self.statements: if not isinstance(stmt, CreateInstanceStmt): continue if stmt.names: fn = self._populate_instance_with_named_arguments else: fn = self._populate_instance_with_positional_arguments fn(metamodel, stmt)
def populate_instances(self, metamodel): ''' Populate a *metamodel* with instances previously encountered from input. ''' for stmt in self.statements: if not isinstance(stmt, CreateInstanceStmt): continue if stmt.names: fn = self._populate_instance_with_named_arguments else: fn = self._populate_instance_with_positional_arguments fn(metamodel, stmt)
[ "Populate", "a", "*", "metamodel", "*", "with", "instances", "previously", "encountered", "from", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L365-L379
[ "def", "populate_instances", "(", "self", ",", "metamodel", ")", ":", "for", "stmt", "in", "self", ".", "statements", ":", "if", "not", "isinstance", "(", "stmt", ",", "CreateInstanceStmt", ")", ":", "continue", "if", "stmt", ".", "names", ":", "fn", "=", "self", ".", "_populate_instance_with_named_arguments", "else", ":", "fn", "=", "self", ".", "_populate_instance_with_positional_arguments", "fn", "(", "metamodel", ",", "stmt", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate_connections
Populate links in a *metamodel* with connections between them.
xtuml/load.py
def populate_connections(self, metamodel): ''' Populate links in a *metamodel* with connections between them. ''' storage = dict() for ass in metamodel.associations: source_class = ass.source_link.to_metaclass target_class = ass.target_link.to_metaclass if target_class not in storage: storage[target_class] = dict() link_key = frozenset(ass.source_link.key_map.values()) if link_key not in storage[target_class]: storage[target_class][link_key] = dict() for other_inst in target_class.storage: inst_key = ass.source_link.compute_index_key(other_inst) if inst_key is None: continue if inst_key not in storage[target_class][link_key]: storage[target_class][link_key][inst_key] = xtuml.OrderedSet() storage[target_class][link_key][inst_key].add(other_inst) for inst in source_class.storage: inst_key = ass.source_link.compute_lookup_key(inst) if inst_key is None: continue if inst_key not in storage[target_class][link_key]: continue for other_inst in storage[target_class][link_key][inst_key]: ass.source_link.connect(other_inst, inst, check=False) ass.target_link.connect(inst, other_inst, check=False) for inst in metamodel.instances: metaclass = xtuml.get_metaclass(inst) for attr in metaclass.referential_attributes: if attr in inst.__dict__: delattr(inst, attr)
def populate_connections(self, metamodel): ''' Populate links in a *metamodel* with connections between them. ''' storage = dict() for ass in metamodel.associations: source_class = ass.source_link.to_metaclass target_class = ass.target_link.to_metaclass if target_class not in storage: storage[target_class] = dict() link_key = frozenset(ass.source_link.key_map.values()) if link_key not in storage[target_class]: storage[target_class][link_key] = dict() for other_inst in target_class.storage: inst_key = ass.source_link.compute_index_key(other_inst) if inst_key is None: continue if inst_key not in storage[target_class][link_key]: storage[target_class][link_key][inst_key] = xtuml.OrderedSet() storage[target_class][link_key][inst_key].add(other_inst) for inst in source_class.storage: inst_key = ass.source_link.compute_lookup_key(inst) if inst_key is None: continue if inst_key not in storage[target_class][link_key]: continue for other_inst in storage[target_class][link_key][inst_key]: ass.source_link.connect(other_inst, inst, check=False) ass.target_link.connect(inst, other_inst, check=False) for inst in metamodel.instances: metaclass = xtuml.get_metaclass(inst) for attr in metaclass.referential_attributes: if attr in inst.__dict__: delattr(inst, attr)
[ "Populate", "links", "in", "a", "*", "metamodel", "*", "with", "connections", "between", "them", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L381-L422
[ "def", "populate_connections", "(", "self", ",", "metamodel", ")", ":", "storage", "=", "dict", "(", ")", "for", "ass", "in", "metamodel", ".", "associations", ":", "source_class", "=", "ass", ".", "source_link", ".", "to_metaclass", "target_class", "=", "ass", ".", "target_link", ".", "to_metaclass", "if", "target_class", "not", "in", "storage", ":", "storage", "[", "target_class", "]", "=", "dict", "(", ")", "link_key", "=", "frozenset", "(", "ass", ".", "source_link", ".", "key_map", ".", "values", "(", ")", ")", "if", "link_key", "not", "in", "storage", "[", "target_class", "]", ":", "storage", "[", "target_class", "]", "[", "link_key", "]", "=", "dict", "(", ")", "for", "other_inst", "in", "target_class", ".", "storage", ":", "inst_key", "=", "ass", ".", "source_link", ".", "compute_index_key", "(", "other_inst", ")", "if", "inst_key", "is", "None", ":", "continue", "if", "inst_key", "not", "in", "storage", "[", "target_class", "]", "[", "link_key", "]", ":", "storage", "[", "target_class", "]", "[", "link_key", "]", "[", "inst_key", "]", "=", "xtuml", ".", "OrderedSet", "(", ")", "storage", "[", "target_class", "]", "[", "link_key", "]", "[", "inst_key", "]", ".", "add", "(", "other_inst", ")", "for", "inst", "in", "source_class", ".", "storage", ":", "inst_key", "=", "ass", ".", "source_link", ".", "compute_lookup_key", "(", "inst", ")", "if", "inst_key", "is", "None", ":", "continue", "if", "inst_key", "not", "in", "storage", "[", "target_class", "]", "[", "link_key", "]", ":", "continue", "for", "other_inst", "in", "storage", "[", "target_class", "]", "[", "link_key", "]", "[", "inst_key", "]", ":", "ass", ".", "source_link", ".", "connect", "(", "other_inst", ",", "inst", ",", "check", "=", "False", ")", "ass", ".", "target_link", ".", "connect", "(", "inst", ",", "other_inst", ",", "check", "=", "False", ")", "for", "inst", "in", "metamodel", ".", "instances", ":", "metaclass", "=", "xtuml", ".", "get_metaclass", "(", "inst", ")", "for", "attr", "in", "metaclass", ".", "referential_attributes", ":", "if", "attr", "in", "inst", ".", "__dict__", ":", "delattr", "(", "inst", ",", "attr", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.populate
Populate a *metamodel* with entities previously encountered from input.
xtuml/load.py
def populate(self, metamodel): ''' Populate a *metamodel* with entities previously encountered from input. ''' self.populate_classes(metamodel) self.populate_unique_identifiers(metamodel) self.populate_associations(metamodel) self.populate_instances(metamodel) self.populate_connections(metamodel)
def populate(self, metamodel): ''' Populate a *metamodel* with entities previously encountered from input. ''' self.populate_classes(metamodel) self.populate_unique_identifiers(metamodel) self.populate_associations(metamodel) self.populate_instances(metamodel) self.populate_connections(metamodel)
[ "Populate", "a", "*", "metamodel", "*", "with", "entities", "previously", "encountered", "from", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L424-L432
[ "def", "populate", "(", "self", ",", "metamodel", ")", ":", "self", ".", "populate_classes", "(", "metamodel", ")", "self", ".", "populate_unique_identifiers", "(", "metamodel", ")", "self", ".", "populate_associations", "(", "metamodel", ")", "self", ".", "populate_instances", "(", "metamodel", ")", "self", ".", "populate_connections", "(", "metamodel", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.build_metamodel
Build and return a *xtuml.MetaModel* containing previously loaded input.
xtuml/load.py
def build_metamodel(self, id_generator=None): ''' Build and return a *xtuml.MetaModel* containing previously loaded input. ''' m = xtuml.MetaModel(id_generator) self.populate(m) return m
def build_metamodel(self, id_generator=None): ''' Build and return a *xtuml.MetaModel* containing previously loaded input. ''' m = xtuml.MetaModel(id_generator) self.populate(m) return m
[ "Build", "and", "return", "a", "*", "xtuml", ".", "MetaModel", "*", "containing", "previously", "loaded", "input", "." ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L434-L442
[ "def", "build_metamodel", "(", "self", ",", "id_generator", "=", "None", ")", ":", "m", "=", "xtuml", ".", "MetaModel", "(", "id_generator", ")", "self", ".", "populate", "(", "m", ")", "return", "m" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_COMMA
r',
xtuml/load.py
def t_COMMA(self, t): r',' t.endlexpos = t.lexpos + len(t.value) return t
def t_COMMA(self, t): r',' t.endlexpos = t.lexpos + len(t.value) return t
[ "r" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L449-L452
[ "def", "t_COMMA", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_FRACTION
r'(\d+)(\.\d+)
xtuml/load.py
def t_FRACTION(self, t): r'(\d+)(\.\d+)' t.endlexpos = t.lexpos + len(t.value) return t
def t_FRACTION(self, t): r'(\d+)(\.\d+)' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "(", "\\", "d", "+", ")", "(", "\\", ".", "\\", "d", "+", ")" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L454-L457
[ "def", "t_FRACTION", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_RELID
r'R[0-9]+
xtuml/load.py
def t_RELID(self, t): r'R[0-9]+' t.endlexpos = t.lexpos + len(t.value) return t
def t_RELID(self, t): r'R[0-9]+' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "R", "[", "0", "-", "9", "]", "+" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L459-L462
[ "def", "t_RELID", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_CARDINALITY
r'(1C)
xtuml/load.py
def t_CARDINALITY(self, t): r'(1C)' t.endlexpos = t.lexpos + len(t.value) return t
def t_CARDINALITY(self, t): r'(1C)' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "(", "1C", ")" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L464-L467
[ "def", "t_CARDINALITY", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_ID
r'[A-Za-z_][\w_]*
xtuml/load.py
def t_ID(self, t): r'[A-Za-z_][\w_]*' vup = t.value.upper() if vup in self.reserved: t.type = vup t.endlexpos = t.lexpos + len(t.value) return t
def t_ID(self, t): r'[A-Za-z_][\w_]*' vup = t.value.upper() if vup in self.reserved: t.type = vup t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "[", "A", "-", "Za", "-", "z_", "]", "[", "\\", "w_", "]", "*" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L469-L475
[ "def", "t_ID", "(", "self", ",", "t", ")", ":", "vup", "=", "t", ".", "value", ".", "upper", "(", ")", "if", "vup", "in", "self", ".", "reserved", ":", "t", ".", "type", "=", "vup", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_LPAREN
r'\(
xtuml/load.py
def t_LPAREN(self, t): r'\(' t.endlexpos = t.lexpos + len(t.value) return t
def t_LPAREN(self, t): r'\(' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "\\", "(" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L477-L480
[ "def", "t_LPAREN", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_MINUS
r'-
xtuml/load.py
def t_MINUS(self, t): r'-' t.endlexpos = t.lexpos + len(t.value) return t
def t_MINUS(self, t): r'-' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "-" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L482-L485
[ "def", "t_MINUS", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_NUMBER
r'[0-9]+
xtuml/load.py
def t_NUMBER(self, t): r'[0-9]+' t.endlexpos = t.lexpos + len(t.value) return t
def t_NUMBER(self, t): r'[0-9]+' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "[", "0", "-", "9", "]", "+" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L487-L490
[ "def", "t_NUMBER", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_RPAREN
r'\)
xtuml/load.py
def t_RPAREN(self, t): r'\)' t.endlexpos = t.lexpos + len(t.value) return t
def t_RPAREN(self, t): r'\)' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "\\", ")" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L492-L495
[ "def", "t_RPAREN", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_SEMICOLON
r';
xtuml/load.py
def t_SEMICOLON(self, t): r';' t.endlexpos = t.lexpos + len(t.value) return t
def t_SEMICOLON(self, t): r';' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", ";" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L497-L500
[ "def", "t_SEMICOLON", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_GUID
r'\"([^\\\n]|(\\.))*?\"
xtuml/load.py
def t_GUID(self, t): r'\"([^\\\n]|(\\.))*?\"' t.endlexpos = t.lexpos + len(t.value) return t
def t_GUID(self, t): r'\"([^\\\n]|(\\.))*?\"' t.endlexpos = t.lexpos + len(t.value) return t
[ "r", "\\", "(", "[", "^", "\\\\\\", "n", "]", "|", "(", "\\\\", ".", "))", "*", "?", "\\" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L508-L511
[ "def", "t_GUID", "(", "self", ",", "t", ")", ":", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")", "return", "t" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.t_newline
r'\n+
xtuml/load.py
def t_newline(self, t): r'\n+' t.lexer.lineno += len(t.value) t.endlexpos = t.lexpos + len(t.value)
def t_newline(self, t): r'\n+' t.lexer.lineno += len(t.value) t.endlexpos = t.lexpos + len(t.value)
[ "r", "\\", "n", "+" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L513-L516
[ "def", "t_newline", "(", "self", ",", "t", ")", ":", "t", ".", "lexer", ".", "lineno", "+=", "len", "(", "t", ".", "value", ")", "t", ".", "endlexpos", "=", "t", ".", "lexpos", "+", "len", "(", "t", ".", "value", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.p_statement
statement : create_table_statement SEMICOLON | insert_into_statement SEMICOLON | create_rop_statement SEMICOLON | create_index_statement SEMICOLON
xtuml/load.py
def p_statement(self, p): ''' statement : create_table_statement SEMICOLON | insert_into_statement SEMICOLON | create_rop_statement SEMICOLON | create_index_statement SEMICOLON ''' p[0] = p[1] p[0].offset = p.lexpos(1) p[0].lineno = p.lineno(1) p[0].filename = p.lexer.filename
def p_statement(self, p): ''' statement : create_table_statement SEMICOLON | insert_into_statement SEMICOLON | create_rop_statement SEMICOLON | create_index_statement SEMICOLON ''' p[0] = p[1] p[0].offset = p.lexpos(1) p[0].lineno = p.lineno(1) p[0].filename = p.lexer.filename
[ "statement", ":", "create_table_statement", "SEMICOLON", "|", "insert_into_statement", "SEMICOLON", "|", "create_rop_statement", "SEMICOLON", "|", "create_index_statement", "SEMICOLON" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L539-L549
[ "def", "p_statement", "(", "self", ",", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "p", "[", "0", "]", ".", "offset", "=", "p", ".", "lexpos", "(", "1", ")", "p", "[", "0", "]", ".", "lineno", "=", "p", ".", "lineno", "(", "1", ")", "p", "[", "0", "]", ".", "filename", "=", "p", ".", "lexer", ".", "filename" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.p_create_rop_statement
create_rop_statement : CREATE ROP REF_ID RELID FROM association_end TO association_end
xtuml/load.py
def p_create_rop_statement(self, p): '''create_rop_statement : CREATE ROP REF_ID RELID FROM association_end TO association_end''' args = [p[4]] args.extend(p[6]) args.extend(p[8]) p[0] = CreateAssociationStmt(*args)
def p_create_rop_statement(self, p): '''create_rop_statement : CREATE ROP REF_ID RELID FROM association_end TO association_end''' args = [p[4]] args.extend(p[6]) args.extend(p[8]) p[0] = CreateAssociationStmt(*args)
[ "create_rop_statement", ":", "CREATE", "ROP", "REF_ID", "RELID", "FROM", "association_end", "TO", "association_end" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L615-L620
[ "def", "p_create_rop_statement", "(", "self", ",", "p", ")", ":", "args", "=", "[", "p", "[", "4", "]", "]", "args", ".", "extend", "(", "p", "[", "6", "]", ")", "args", ".", "extend", "(", "p", "[", "8", "]", ")", "p", "[", "0", "]", "=", "CreateAssociationStmt", "(", "*", "args", ")" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.p_cardinality_1
cardinality : NUMBER
xtuml/load.py
def p_cardinality_1(self, p): '''cardinality : NUMBER''' if p[1] != '1': raise ParsingException("illegal cardinality (%s) at %s:%d" % (p[1], p.lexer.filename, p.lineno(1))) p[0] = p[1]
def p_cardinality_1(self, p): '''cardinality : NUMBER''' if p[1] != '1': raise ParsingException("illegal cardinality (%s) at %s:%d" % (p[1], p.lexer.filename, p.lineno(1))) p[0] = p[1]
[ "cardinality", ":", "NUMBER" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L630-L635
[ "def", "p_cardinality_1", "(", "self", ",", "p", ")", ":", "if", "p", "[", "1", "]", "!=", "'1'", ":", "raise", "ParsingException", "(", "\"illegal cardinality (%s) at %s:%d\"", "%", "(", "p", "[", "1", "]", ",", "p", ".", "lexer", ".", "filename", ",", "p", ".", "lineno", "(", "1", ")", ")", ")", "p", "[", "0", "]", "=", "p", "[", "1", "]" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
ModelLoader.p_cardinality_many
cardinality : ID
xtuml/load.py
def p_cardinality_many(self, p): '''cardinality : ID''' if p[1] not in ['M', 'MC']: raise ParsingException("illegal cardinality (%s) at %s:%d" % (p[1], p.lexer.filename, p.lineno(1))) p[0] = p[1]
def p_cardinality_many(self, p): '''cardinality : ID''' if p[1] not in ['M', 'MC']: raise ParsingException("illegal cardinality (%s) at %s:%d" % (p[1], p.lexer.filename, p.lineno(1))) p[0] = p[1]
[ "cardinality", ":", "ID" ]
xtuml/pyxtuml
python
https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/xtuml/load.py#L637-L642
[ "def", "p_cardinality_many", "(", "self", ",", "p", ")", ":", "if", "p", "[", "1", "]", "not", "in", "[", "'M'", ",", "'MC'", "]", ":", "raise", "ParsingException", "(", "\"illegal cardinality (%s) at %s:%d\"", "%", "(", "p", "[", "1", "]", ",", "p", ".", "lexer", ".", "filename", ",", "p", ".", "lineno", "(", "1", ")", ")", ")", "p", "[", "0", "]", "=", "p", "[", "1", "]" ]
7dd9343b9a0191d1db1887ab9288d0a026608d9a
test
Searcher.append_known_secrets
Read key-value pair files with secrets. For example, .conf and .ini files. :return:
find_known_secrets/searcher.py
def append_known_secrets(self): # type: () -> None """ Read key-value pair files with secrets. For example, .conf and .ini files. :return: """ for file_name in self.files: if "~" in file_name: file_name = os.path.expanduser(file_name) if not os.path.isfile(file_name): print( "Don't have " + Back.BLACK + Fore.YELLOW + file_name + ", won't use." ) continue with open(os.path.expanduser(file_name), "r") as file: for line in file: if line and "=" in line: possible = line.split("=")[1].strip(" \"'\n") if len(possible) > 4 and possible not in self.false_positives: self.secrets.append(possible)
def append_known_secrets(self): # type: () -> None """ Read key-value pair files with secrets. For example, .conf and .ini files. :return: """ for file_name in self.files: if "~" in file_name: file_name = os.path.expanduser(file_name) if not os.path.isfile(file_name): print( "Don't have " + Back.BLACK + Fore.YELLOW + file_name + ", won't use." ) continue with open(os.path.expanduser(file_name), "r") as file: for line in file: if line and "=" in line: possible = line.split("=")[1].strip(" \"'\n") if len(possible) > 4 and possible not in self.false_positives: self.secrets.append(possible)
[ "Read", "key", "-", "value", "pair", "files", "with", "secrets", ".", "For", "example", ".", "conf", "and", ".", "ini", "files", ".", ":", "return", ":" ]
matthewdeanmartin/find_known_secrets
python
https://github.com/matthewdeanmartin/find_known_secrets/blob/f25735c1ab4512bad85ade33af7021f6fac1d13b/find_known_secrets/searcher.py#L58-L80
[ "def", "append_known_secrets", "(", "self", ")", ":", "# type: () -> None", "for", "file_name", "in", "self", ".", "files", ":", "if", "\"~\"", "in", "file_name", ":", "file_name", "=", "os", ".", "path", ".", "expanduser", "(", "file_name", ")", "if", "not", "os", ".", "path", ".", "isfile", "(", "file_name", ")", ":", "print", "(", "\"Don't have \"", "+", "Back", ".", "BLACK", "+", "Fore", ".", "YELLOW", "+", "file_name", "+", "\", won't use.\"", ")", "continue", "with", "open", "(", "os", ".", "path", ".", "expanduser", "(", "file_name", ")", ",", "\"r\"", ")", "as", "file", ":", "for", "line", "in", "file", ":", "if", "line", "and", "\"=\"", "in", "line", ":", "possible", "=", "line", ".", "split", "(", "\"=\"", ")", "[", "1", "]", ".", "strip", "(", "\" \\\"'\\n\"", ")", "if", "len", "(", "possible", ")", ">", "4", "and", "possible", "not", "in", "self", ".", "false_positives", ":", "self", ".", "secrets", ".", "append", "(", "possible", ")" ]
f25735c1ab4512bad85ade33af7021f6fac1d13b
test
Searcher.search_known_secrets
Search a path for known secrets, outputing text and file when found :return:
find_known_secrets/searcher.py
def search_known_secrets(self): # type: () -> None """ Search a path for known secrets, outputing text and file when found :return: """ count = 0 here = os.path.abspath(self.source) # python 3 only! # for file in glob.glob(here + "/" + "**/*.*", recursive=True): # py 2 matches = [] for root, dirnames, filenames in os.walk(here + "/"): for filename in filenames: matches.append(os.path.join(root, filename)) for file in matches: if os.path.isdir(file): continue with open(file) as f: try: contents = f.read() except UnicodeDecodeError: continue except Exception as e: print(e) print(file) raise for secret in self.secrets: if secret in contents: for line in contents.split("\n"): if secret in line: self.found.setdefault(file, []).append( ( secret, line.replace( secret, Fore.RED + Back.YELLOW + secret + Style.RESET_ALL, ), ) ) count += 1
def search_known_secrets(self): # type: () -> None """ Search a path for known secrets, outputing text and file when found :return: """ count = 0 here = os.path.abspath(self.source) # python 3 only! # for file in glob.glob(here + "/" + "**/*.*", recursive=True): # py 2 matches = [] for root, dirnames, filenames in os.walk(here + "/"): for filename in filenames: matches.append(os.path.join(root, filename)) for file in matches: if os.path.isdir(file): continue with open(file) as f: try: contents = f.read() except UnicodeDecodeError: continue except Exception as e: print(e) print(file) raise for secret in self.secrets: if secret in contents: for line in contents.split("\n"): if secret in line: self.found.setdefault(file, []).append( ( secret, line.replace( secret, Fore.RED + Back.YELLOW + secret + Style.RESET_ALL, ), ) ) count += 1
[ "Search", "a", "path", "for", "known", "secrets", "outputing", "text", "and", "file", "when", "found", ":", "return", ":" ]
matthewdeanmartin/find_known_secrets
python
https://github.com/matthewdeanmartin/find_known_secrets/blob/f25735c1ab4512bad85ade33af7021f6fac1d13b/find_known_secrets/searcher.py#L82-L126
[ "def", "search_known_secrets", "(", "self", ")", ":", "# type: () -> None", "count", "=", "0", "here", "=", "os", ".", "path", ".", "abspath", "(", "self", ".", "source", ")", "# python 3 only!", "# for file in glob.glob(here + \"/\" + \"**/*.*\", recursive=True):", "# py 2", "matches", "=", "[", "]", "for", "root", ",", "dirnames", ",", "filenames", "in", "os", ".", "walk", "(", "here", "+", "\"/\"", ")", ":", "for", "filename", "in", "filenames", ":", "matches", ".", "append", "(", "os", ".", "path", ".", "join", "(", "root", ",", "filename", ")", ")", "for", "file", "in", "matches", ":", "if", "os", ".", "path", ".", "isdir", "(", "file", ")", ":", "continue", "with", "open", "(", "file", ")", "as", "f", ":", "try", ":", "contents", "=", "f", ".", "read", "(", ")", "except", "UnicodeDecodeError", ":", "continue", "except", "Exception", "as", "e", ":", "print", "(", "e", ")", "print", "(", "file", ")", "raise", "for", "secret", "in", "self", ".", "secrets", ":", "if", "secret", "in", "contents", ":", "for", "line", "in", "contents", ".", "split", "(", "\"\\n\"", ")", ":", "if", "secret", "in", "line", ":", "self", ".", "found", ".", "setdefault", "(", "file", ",", "[", "]", ")", ".", "append", "(", "(", "secret", ",", "line", ".", "replace", "(", "secret", ",", "Fore", ".", "RED", "+", "Back", ".", "YELLOW", "+", "secret", "+", "Style", ".", "RESET_ALL", ",", ")", ",", ")", ")", "count", "+=", "1" ]
f25735c1ab4512bad85ade33af7021f6fac1d13b
test
eid
Encode id (bytes) as a Unicode string. The encoding is done such that lexicographic order is preserved. No concern is given to wasting space. The inverse of ``eid`` is ``did``.
dossier/store/elastic.py
def eid(s): '''Encode id (bytes) as a Unicode string. The encoding is done such that lexicographic order is preserved. No concern is given to wasting space. The inverse of ``eid`` is ``did``. ''' if isinstance(s, unicode): s = s.encode('utf-8') return u''.join('{:02x}'.format(ord(b)) for b in s)
def eid(s): '''Encode id (bytes) as a Unicode string. The encoding is done such that lexicographic order is preserved. No concern is given to wasting space. The inverse of ``eid`` is ``did``. ''' if isinstance(s, unicode): s = s.encode('utf-8') return u''.join('{:02x}'.format(ord(b)) for b in s)
[ "Encode", "id", "(", "bytes", ")", "as", "a", "Unicode", "string", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L861-L871
[ "def", "eid", "(", "s", ")", ":", "if", "isinstance", "(", "s", ",", "unicode", ")", ":", "s", "=", "s", ".", "encode", "(", "'utf-8'", ")", "return", "u''", ".", "join", "(", "'{:02x}'", ".", "format", "(", "ord", "(", "b", ")", ")", "for", "b", "in", "s", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
did
Decode id (Unicode string) as a bytes. The inverse of ``did`` is ``eid``.
dossier/store/elastic.py
def did(s): '''Decode id (Unicode string) as a bytes. The inverse of ``did`` is ``eid``. ''' return ''.join(chr(int(s[i:i+2], base=16)) for i in xrange(0, len(s), 2))
def did(s): '''Decode id (Unicode string) as a bytes. The inverse of ``did`` is ``eid``. ''' return ''.join(chr(int(s[i:i+2], base=16)) for i in xrange(0, len(s), 2))
[ "Decode", "id", "(", "Unicode", "string", ")", "as", "a", "bytes", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L874-L879
[ "def", "did", "(", "s", ")", ":", "return", "''", ".", "join", "(", "chr", "(", "int", "(", "s", "[", "i", ":", "i", "+", "2", "]", ",", "base", "=", "16", ")", ")", "for", "i", "in", "xrange", "(", "0", ",", "len", "(", "s", ")", ",", "2", ")", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.get
Retrieve a feature collection. If a feature collection with the given id does not exist, then ``None`` is returned. :param str content_id: Content identifier. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: :class:`dossier.fc.FeatureCollection` or ``None``
dossier/store/elastic.py
def get(self, content_id, feature_names=None): '''Retrieve a feature collection. If a feature collection with the given id does not exist, then ``None`` is returned. :param str content_id: Content identifier. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: :class:`dossier.fc.FeatureCollection` or ``None`` ''' try: resp = self.conn.get(index=self.index, doc_type=self.type, id=eid(content_id), _source=self._source(feature_names)) return self.fc_from_dict(resp['_source']['fc']) except NotFoundError: return None except: raise
def get(self, content_id, feature_names=None): '''Retrieve a feature collection. If a feature collection with the given id does not exist, then ``None`` is returned. :param str content_id: Content identifier. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: :class:`dossier.fc.FeatureCollection` or ``None`` ''' try: resp = self.conn.get(index=self.index, doc_type=self.type, id=eid(content_id), _source=self._source(feature_names)) return self.fc_from_dict(resp['_source']['fc']) except NotFoundError: return None except: raise
[ "Retrieve", "a", "feature", "collection", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L140-L160
[ "def", "get", "(", "self", ",", "content_id", ",", "feature_names", "=", "None", ")", ":", "try", ":", "resp", "=", "self", ".", "conn", ".", "get", "(", "index", "=", "self", ".", "index", ",", "doc_type", "=", "self", ".", "type", ",", "id", "=", "eid", "(", "content_id", ")", ",", "_source", "=", "self", ".", "_source", "(", "feature_names", ")", ")", "return", "self", ".", "fc_from_dict", "(", "resp", "[", "'_source'", "]", "[", "'fc'", "]", ")", "except", "NotFoundError", ":", "return", "None", "except", ":", "raise" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.get_many
Returns an iterable of feature collections. This efficiently retrieves multiple FCs corresponding to the list of ids given. Tuples of identifier and feature collection are yielded. If the feature collection for a given id does not exist, then ``None`` is returned as the second element of the tuple. :param [str] content_ids: List of content ids. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)``
dossier/store/elastic.py
def get_many(self, content_ids, feature_names=None): '''Returns an iterable of feature collections. This efficiently retrieves multiple FCs corresponding to the list of ids given. Tuples of identifier and feature collection are yielded. If the feature collection for a given id does not exist, then ``None`` is returned as the second element of the tuple. :param [str] content_ids: List of content ids. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' try: resp = self.conn.mget(index=self.index, doc_type=self.type, _source=self._source(feature_names), body={'ids': map(eid, content_ids)}) except TransportError: return for doc in resp['docs']: fc = None if doc['found']: fc = self.fc_from_dict(doc['_source']['fc']) yield did(doc['_id']), fc
def get_many(self, content_ids, feature_names=None): '''Returns an iterable of feature collections. This efficiently retrieves multiple FCs corresponding to the list of ids given. Tuples of identifier and feature collection are yielded. If the feature collection for a given id does not exist, then ``None`` is returned as the second element of the tuple. :param [str] content_ids: List of content ids. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' try: resp = self.conn.mget(index=self.index, doc_type=self.type, _source=self._source(feature_names), body={'ids': map(eid, content_ids)}) except TransportError: return for doc in resp['docs']: fc = None if doc['found']: fc = self.fc_from_dict(doc['_source']['fc']) yield did(doc['_id']), fc
[ "Returns", "an", "iterable", "of", "feature", "collections", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L162-L187
[ "def", "get_many", "(", "self", ",", "content_ids", ",", "feature_names", "=", "None", ")", ":", "try", ":", "resp", "=", "self", ".", "conn", ".", "mget", "(", "index", "=", "self", ".", "index", ",", "doc_type", "=", "self", ".", "type", ",", "_source", "=", "self", ".", "_source", "(", "feature_names", ")", ",", "body", "=", "{", "'ids'", ":", "map", "(", "eid", ",", "content_ids", ")", "}", ")", "except", "TransportError", ":", "return", "for", "doc", "in", "resp", "[", "'docs'", "]", ":", "fc", "=", "None", "if", "doc", "[", "'found'", "]", ":", "fc", "=", "self", ".", "fc_from_dict", "(", "doc", "[", "'_source'", "]", "[", "'fc'", "]", ")", "yield", "did", "(", "doc", "[", "'_id'", "]", ")", ",", "fc" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.put
Adds feature collections to the store. This efficiently adds multiple FCs to the store. The iterable of ``items`` given should yield tuples of ``(content_id, FC)``. :param items: Iterable of ``(content_id, FC)``. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed.
dossier/store/elastic.py
def put(self, items, indexes=True): '''Adds feature collections to the store. This efficiently adds multiple FCs to the store. The iterable of ``items`` given should yield tuples of ``(content_id, FC)``. :param items: Iterable of ``(content_id, FC)``. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. ''' actions = [] for cid, fc in items: # TODO: If we store features in a columnar order, then we # could tell ES to index the feature values directly. ---AG # (But is problematic because we want to preserve the ability # to selectively index FCs. So we'd probably need two distinct # doc types.) idxs = defaultdict(list) if indexes: for fname in self.indexed_features: if fname in fc: idxs[fname_to_idx_name(fname)].extend(fc[fname]) for fname in self.fulltext_indexed_features: if fname not in fc: continue if isinstance(fc[fname], basestring): idxs[fname_to_full_idx_name(fname)] = fc[fname] else: idxs[fname_to_full_idx_name(fname)].extend(fc[fname]) actions.append({ '_index': self.index, '_type': self.type, '_id': eid(cid), '_op_type': 'index', '_source': dict(idxs, **{ 'fc': self.fc_to_dict(fc), }), }) bulk(self.conn, actions, timeout=60, request_timeout=60)
def put(self, items, indexes=True): '''Adds feature collections to the store. This efficiently adds multiple FCs to the store. The iterable of ``items`` given should yield tuples of ``(content_id, FC)``. :param items: Iterable of ``(content_id, FC)``. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. ''' actions = [] for cid, fc in items: # TODO: If we store features in a columnar order, then we # could tell ES to index the feature values directly. ---AG # (But is problematic because we want to preserve the ability # to selectively index FCs. So we'd probably need two distinct # doc types.) idxs = defaultdict(list) if indexes: for fname in self.indexed_features: if fname in fc: idxs[fname_to_idx_name(fname)].extend(fc[fname]) for fname in self.fulltext_indexed_features: if fname not in fc: continue if isinstance(fc[fname], basestring): idxs[fname_to_full_idx_name(fname)] = fc[fname] else: idxs[fname_to_full_idx_name(fname)].extend(fc[fname]) actions.append({ '_index': self.index, '_type': self.type, '_id': eid(cid), '_op_type': 'index', '_source': dict(idxs, **{ 'fc': self.fc_to_dict(fc), }), }) bulk(self.conn, actions, timeout=60, request_timeout=60)
[ "Adds", "feature", "collections", "to", "the", "store", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L189-L228
[ "def", "put", "(", "self", ",", "items", ",", "indexes", "=", "True", ")", ":", "actions", "=", "[", "]", "for", "cid", ",", "fc", "in", "items", ":", "# TODO: If we store features in a columnar order, then we", "# could tell ES to index the feature values directly. ---AG", "# (But is problematic because we want to preserve the ability", "# to selectively index FCs. So we'd probably need two distinct", "# doc types.)", "idxs", "=", "defaultdict", "(", "list", ")", "if", "indexes", ":", "for", "fname", "in", "self", ".", "indexed_features", ":", "if", "fname", "in", "fc", ":", "idxs", "[", "fname_to_idx_name", "(", "fname", ")", "]", ".", "extend", "(", "fc", "[", "fname", "]", ")", "for", "fname", "in", "self", ".", "fulltext_indexed_features", ":", "if", "fname", "not", "in", "fc", ":", "continue", "if", "isinstance", "(", "fc", "[", "fname", "]", ",", "basestring", ")", ":", "idxs", "[", "fname_to_full_idx_name", "(", "fname", ")", "]", "=", "fc", "[", "fname", "]", "else", ":", "idxs", "[", "fname_to_full_idx_name", "(", "fname", ")", "]", ".", "extend", "(", "fc", "[", "fname", "]", ")", "actions", ".", "append", "(", "{", "'_index'", ":", "self", ".", "index", ",", "'_type'", ":", "self", ".", "type", ",", "'_id'", ":", "eid", "(", "cid", ")", ",", "'_op_type'", ":", "'index'", ",", "'_source'", ":", "dict", "(", "idxs", ",", "*", "*", "{", "'fc'", ":", "self", ".", "fc_to_dict", "(", "fc", ")", ",", "}", ")", ",", "}", ")", "bulk", "(", "self", ".", "conn", ",", "actions", ",", "timeout", "=", "60", ",", "request_timeout", "=", "60", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.delete
Deletes the corresponding feature collection. If the FC does not exist, then this is a no-op.
dossier/store/elastic.py
def delete(self, content_id): '''Deletes the corresponding feature collection. If the FC does not exist, then this is a no-op. ''' try: self.conn.delete(index=self.index, doc_type=self.type, id=eid(content_id)) except NotFoundError: pass
def delete(self, content_id): '''Deletes the corresponding feature collection. If the FC does not exist, then this is a no-op. ''' try: self.conn.delete(index=self.index, doc_type=self.type, id=eid(content_id)) except NotFoundError: pass
[ "Deletes", "the", "corresponding", "feature", "collection", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L230-L239
[ "def", "delete", "(", "self", ",", "content_id", ")", ":", "try", ":", "self", ".", "conn", ".", "delete", "(", "index", "=", "self", ".", "index", ",", "doc_type", "=", "self", ".", "type", ",", "id", "=", "eid", "(", "content_id", ")", ")", "except", "NotFoundError", ":", "pass" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.delete_all
Deletes all feature collections. This does not destroy the ES index, but instead only deletes all FCs with the configured document type (defaults to ``fc``).
dossier/store/elastic.py
def delete_all(self): '''Deletes all feature collections. This does not destroy the ES index, but instead only deletes all FCs with the configured document type (defaults to ``fc``). ''' try: self.conn.indices.delete_mapping( index=self.index, doc_type=self.type) except TransportError: logger.warn('type %r in index %r already deleted', self.index, self.type, exc_info=True)
def delete_all(self): '''Deletes all feature collections. This does not destroy the ES index, but instead only deletes all FCs with the configured document type (defaults to ``fc``). ''' try: self.conn.indices.delete_mapping( index=self.index, doc_type=self.type) except TransportError: logger.warn('type %r in index %r already deleted', self.index, self.type, exc_info=True)
[ "Deletes", "all", "feature", "collections", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L241-L253
[ "def", "delete_all", "(", "self", ")", ":", "try", ":", "self", ".", "conn", ".", "indices", ".", "delete_mapping", "(", "index", "=", "self", ".", "index", ",", "doc_type", "=", "self", ".", "type", ")", "except", "TransportError", ":", "logger", ".", "warn", "(", "'type %r in index %r already deleted'", ",", "self", ".", "index", ",", "self", ".", "type", ",", "exc_info", "=", "True", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.delete_index
Deletes the underlying ES index. Only use this if you know what you're doing. This destroys the entire underlying ES index, which could be shared by multiple distinct ElasticStore instances.
dossier/store/elastic.py
def delete_index(self): '''Deletes the underlying ES index. Only use this if you know what you're doing. This destroys the entire underlying ES index, which could be shared by multiple distinct ElasticStore instances. ''' if self.conn.indices.exists(index=self.index): self.conn.indices.delete(index=self.index)
def delete_index(self): '''Deletes the underlying ES index. Only use this if you know what you're doing. This destroys the entire underlying ES index, which could be shared by multiple distinct ElasticStore instances. ''' if self.conn.indices.exists(index=self.index): self.conn.indices.delete(index=self.index)
[ "Deletes", "the", "underlying", "ES", "index", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L255-L263
[ "def", "delete_index", "(", "self", ")", ":", "if", "self", ".", "conn", ".", "indices", ".", "exists", "(", "index", "=", "self", ".", "index", ")", ":", "self", ".", "conn", ".", "indices", ".", "delete", "(", "index", "=", "self", ".", "index", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.scan
Scan for FCs in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)``
dossier/store/elastic.py
def scan(self, *key_ranges, **kwargs): '''Scan for FCs in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' for hit in self._scan(*key_ranges, **kwargs): yield did(hit['_id']), self.fc_from_dict(hit['_source']['fc'])
def scan(self, *key_ranges, **kwargs): '''Scan for FCs in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' for hit in self._scan(*key_ranges, **kwargs): yield did(hit['_id']), self.fc_from_dict(hit['_source']['fc'])
[ "Scan", "for", "FCs", "in", "the", "given", "id", "ranges", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L275-L290
[ "def", "scan", "(", "self", ",", "*", "key_ranges", ",", "*", "*", "kwargs", ")", ":", "for", "hit", "in", "self", ".", "_scan", "(", "*", "key_ranges", ",", "*", "*", "kwargs", ")", ":", "yield", "did", "(", "hit", "[", "'_id'", "]", ")", ",", "self", ".", "fc_from_dict", "(", "hit", "[", "'_source'", "]", "[", "'fc'", "]", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.scan_ids
Scan for ids only in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id``
dossier/store/elastic.py
def scan_ids(self, *key_ranges, **kwargs): '''Scan for ids only in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id`` ''' kwargs['feature_names'] = False for hit in self._scan(*key_ranges, **kwargs): yield did(hit['_id'])
def scan_ids(self, *key_ranges, **kwargs): '''Scan for ids only in the given id ranges. :param key_ranges: ``key_ranges`` should be a list of pairs of ranges. The first value is the lower bound id and the second value is the upper bound id. Use ``()`` in either position to leave it unbounded. If no ``key_ranges`` are given, then all FCs in the store are returned. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id`` ''' kwargs['feature_names'] = False for hit in self._scan(*key_ranges, **kwargs): yield did(hit['_id'])
[ "Scan", "for", "ids", "only", "in", "the", "given", "id", "ranges", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L292-L308
[ "def", "scan_ids", "(", "self", ",", "*", "key_ranges", ",", "*", "*", "kwargs", ")", ":", "kwargs", "[", "'feature_names'", "]", "=", "False", "for", "hit", "in", "self", ".", "_scan", "(", "*", "key_ranges", ",", "*", "*", "kwargs", ")", ":", "yield", "did", "(", "hit", "[", "'_id'", "]", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.scan_prefix
Scan for FCs with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)``
dossier/store/elastic.py
def scan_prefix(self, prefix, feature_names=None): '''Scan for FCs with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' resp = self._scan_prefix(prefix, feature_names=feature_names) for hit in resp: yield did(hit['_id']), self.fc_from_dict(hit['_source']['fc'])
def scan_prefix(self, prefix, feature_names=None): '''Scan for FCs with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' resp = self._scan_prefix(prefix, feature_names=feature_names) for hit in resp: yield did(hit['_id']), self.fc_from_dict(hit['_source']['fc'])
[ "Scan", "for", "FCs", "with", "a", "given", "prefix", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L310-L321
[ "def", "scan_prefix", "(", "self", ",", "prefix", ",", "feature_names", "=", "None", ")", ":", "resp", "=", "self", ".", "_scan_prefix", "(", "prefix", ",", "feature_names", "=", "feature_names", ")", "for", "hit", "in", "resp", ":", "yield", "did", "(", "hit", "[", "'_id'", "]", ")", ",", "self", ".", "fc_from_dict", "(", "hit", "[", "'_source'", "]", "[", "'fc'", "]", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.scan_prefix_ids
Scan for ids with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id``
dossier/store/elastic.py
def scan_prefix_ids(self, prefix): '''Scan for ids with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id`` ''' resp = self._scan_prefix(prefix, feature_names=False) for hit in resp: yield did(hit['_id'])
def scan_prefix_ids(self, prefix): '''Scan for ids with a given prefix. :param str prefix: Identifier prefix. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``content_id`` ''' resp = self._scan_prefix(prefix, feature_names=False) for hit in resp: yield did(hit['_id'])
[ "Scan", "for", "ids", "with", "a", "given", "prefix", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L323-L334
[ "def", "scan_prefix_ids", "(", "self", ",", "prefix", ")", ":", "resp", "=", "self", ".", "_scan_prefix", "(", "prefix", ",", "feature_names", "=", "False", ")", "for", "hit", "in", "resp", ":", "yield", "did", "(", "hit", "[", "'_id'", "]", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.fulltext_scan
Fulltext search. Yields an iterable of triples (score, identifier, FC) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(score, content_id, FC)``
dossier/store/elastic.py
def fulltext_scan(self, query_id=None, query_fc=None, feature_names=None, preserve_order=True, indexes=None): '''Fulltext search. Yields an iterable of triples (score, identifier, FC) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(score, content_id, FC)`` ''' it = self._fulltext_scan(query_id, query_fc, feature_names=feature_names, preserve_order=preserve_order, indexes=indexes) for hit in it: fc = self.fc_from_dict(hit['_source']['fc']) yield hit['_score'], did(hit['_id']), fc
def fulltext_scan(self, query_id=None, query_fc=None, feature_names=None, preserve_order=True, indexes=None): '''Fulltext search. Yields an iterable of triples (score, identifier, FC) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(score, content_id, FC)`` ''' it = self._fulltext_scan(query_id, query_fc, feature_names=feature_names, preserve_order=preserve_order, indexes=indexes) for hit in it: fc = self.fc_from_dict(hit['_source']['fc']) yield hit['_score'], did(hit['_id']), fc
[ "Fulltext", "search", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L336-L366
[ "def", "fulltext_scan", "(", "self", ",", "query_id", "=", "None", ",", "query_fc", "=", "None", ",", "feature_names", "=", "None", ",", "preserve_order", "=", "True", ",", "indexes", "=", "None", ")", ":", "it", "=", "self", ".", "_fulltext_scan", "(", "query_id", ",", "query_fc", ",", "feature_names", "=", "feature_names", ",", "preserve_order", "=", "preserve_order", ",", "indexes", "=", "indexes", ")", "for", "hit", "in", "it", ":", "fc", "=", "self", ".", "fc_from_dict", "(", "hit", "[", "'_source'", "]", "[", "'fc'", "]", ")", "yield", "hit", "[", "'_score'", "]", ",", "did", "(", "hit", "[", "'_id'", "]", ")", ",", "fc" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.fulltext_scan_ids
Fulltext search for identifiers. Yields an iterable of triples (score, identifier) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :rtype: Iterable of ``(score, content_id)``
dossier/store/elastic.py
def fulltext_scan_ids(self, query_id=None, query_fc=None, preserve_order=True, indexes=None): '''Fulltext search for identifiers. Yields an iterable of triples (score, identifier) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :rtype: Iterable of ``(score, content_id)`` ''' it = self._fulltext_scan(query_id, query_fc, feature_names=False, preserve_order=preserve_order, indexes=indexes) for hit in it: yield hit['_score'], did(hit['_id'])
def fulltext_scan_ids(self, query_id=None, query_fc=None, preserve_order=True, indexes=None): '''Fulltext search for identifiers. Yields an iterable of triples (score, identifier) corresponding to the search results of the fulltext search in ``query``. This will only search text indexed under the given feature named ``fname``. Note that, unless ``preserve_order`` is set to True, the ``score`` will always be 0.0, and the results will be unordered. ``preserve_order`` set to True will cause the results to be scored and be ordered by score, but you should expect to see a decrease in performance. :param str fname: The feature to search. :param unicode query: The query. :rtype: Iterable of ``(score, content_id)`` ''' it = self._fulltext_scan(query_id, query_fc, feature_names=False, preserve_order=preserve_order, indexes=indexes) for hit in it: yield hit['_score'], did(hit['_id'])
[ "Fulltext", "search", "for", "identifiers", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L368-L393
[ "def", "fulltext_scan_ids", "(", "self", ",", "query_id", "=", "None", ",", "query_fc", "=", "None", ",", "preserve_order", "=", "True", ",", "indexes", "=", "None", ")", ":", "it", "=", "self", ".", "_fulltext_scan", "(", "query_id", ",", "query_fc", ",", "feature_names", "=", "False", ",", "preserve_order", "=", "preserve_order", ",", "indexes", "=", "indexes", ")", "for", "hit", "in", "it", ":", "yield", "hit", "[", "'_score'", "]", ",", "did", "(", "hit", "[", "'_id'", "]", ")" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f
test
ElasticStore.keyword_scan
Keyword scan for feature collections. This performs a keyword scan using the query given. A keyword scan searches for FCs with terms in each of the query's indexed fields. At least one of ``query_id`` or ``query_fc`` must be provided. If ``query_fc`` is ``None``, then the query is retrieved automatically corresponding to ``query_id``. :param str query_id: Optional query id. :param query_fc: Optional query feature collection. :type query_fc: :class:`dossier.fc.FeatureCollection` :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)``
dossier/store/elastic.py
def keyword_scan(self, query_id=None, query_fc=None, feature_names=None): '''Keyword scan for feature collections. This performs a keyword scan using the query given. A keyword scan searches for FCs with terms in each of the query's indexed fields. At least one of ``query_id`` or ``query_fc`` must be provided. If ``query_fc`` is ``None``, then the query is retrieved automatically corresponding to ``query_id``. :param str query_id: Optional query id. :param query_fc: Optional query feature collection. :type query_fc: :class:`dossier.fc.FeatureCollection` :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' it = self._keyword_scan(query_id, query_fc, feature_names=feature_names) for hit in it: fc = self.fc_from_dict(hit['_source']['fc']) yield did(hit['_id']), fc
def keyword_scan(self, query_id=None, query_fc=None, feature_names=None): '''Keyword scan for feature collections. This performs a keyword scan using the query given. A keyword scan searches for FCs with terms in each of the query's indexed fields. At least one of ``query_id`` or ``query_fc`` must be provided. If ``query_fc`` is ``None``, then the query is retrieved automatically corresponding to ``query_id``. :param str query_id: Optional query id. :param query_fc: Optional query feature collection. :type query_fc: :class:`dossier.fc.FeatureCollection` :param [str] feature_names: A list of feature names to retrieve. When ``None``, all features are retrieved. Wildcards are allowed. :rtype: Iterable of ``(content_id, FC)`` ''' it = self._keyword_scan(query_id, query_fc, feature_names=feature_names) for hit in it: fc = self.fc_from_dict(hit['_source']['fc']) yield did(hit['_id']), fc
[ "Keyword", "scan", "for", "feature", "collections", "." ]
dossier/dossier.store
python
https://github.com/dossier/dossier.store/blob/b22ffe2470bba9fcc98a30cb55b437bfa1521e7f/dossier/store/elastic.py#L395-L418
[ "def", "keyword_scan", "(", "self", ",", "query_id", "=", "None", ",", "query_fc", "=", "None", ",", "feature_names", "=", "None", ")", ":", "it", "=", "self", ".", "_keyword_scan", "(", "query_id", ",", "query_fc", ",", "feature_names", "=", "feature_names", ")", "for", "hit", "in", "it", ":", "fc", "=", "self", ".", "fc_from_dict", "(", "hit", "[", "'_source'", "]", "[", "'fc'", "]", ")", "yield", "did", "(", "hit", "[", "'_id'", "]", ")", ",", "fc" ]
b22ffe2470bba9fcc98a30cb55b437bfa1521e7f