_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q279000
RPCSystem.create_function_stub
test
def create_function_stub(self, url): """ Create a callable that will invoke the given remote function. The stub will return a deferred even if the remote function does not. """ assert self._opened, "RPC System is not opened" logging.debug("create_function_stub(%s)" % repr(url)) parseresult = urlparse.urlparse(url) scheme = parseresult.scheme path = parseresult.path.split("/") if scheme != "anycall": raise ValueError("Not an anycall URL: %s" % repr(url)) if len(path) != 3 or path[0] != "" or path[1] != "functions":
python
{ "resource": "" }
q279001
RPCSystem._ping
test
def _ping(self, peerid, callid): """ Called from remote to ask if a call made to here is still in progress.
python
{ "resource": "" }
q279002
_CommandCompleterMixin._cmdRegex
test
def _cmdRegex(self, cmd_grp=None): """Get command regex string and completer dict.""" cmd_grp = cmd_grp or "cmd" help_opts = ("-h", "--help") cmd = self.name() names = "|".join([re.escape(cmd)] + [re.escape(a) for a in self.aliases()]) opts = [] for action in self.parser._actions: opts += [a for a in action.option_strings if a not in help_opts] opts_re = "|".join([re.escape(o) for o in opts]) if opts_re: opts_re = rf"(\s+(?P<{cmd_grp}_opts>{opts_re}))*"
python
{ "resource": "" }
q279003
NestedAMPBox.fromStringProto
test
def fromStringProto(self, inString, proto): """ Defers to `amp.AmpList`, then gets the element from the list. """
python
{ "resource": "" }
q279004
NestedAMPBox.toStringProto
test
def toStringProto(self, inObject, proto): """ Wraps the object in a list, and then defers to ``amp.AmpList``. """
python
{ "resource": "" }
q279005
MetadataStatement.verify
test
def verify(self, **kwargs): """ Verifies that an instance of this class adheres to the given restrictions. :param kwargs: A set of keyword arguments :return: True if it verifies OK otherwise False. """ super(MetadataStatement, self).verify(**kwargs) if "signing_keys" in self: if 'signing_keys_uri' in self: raise VerificationError( 'You can only have one of "signing_keys" and ' '"signing_keys_uri" in a metadata statement') else: # signing_keys MUST be a JWKS kj = KeyJar() try: kj.import_jwks(self['signing_keys'], '') except Exception: raise VerificationError('"signing_keys" not a proper JWKS')
python
{ "resource": "" }
q279006
KeyBundle._parse_remote_response
test
def _parse_remote_response(self, response): """ Parse simple JWKS or signed JWKS from the HTTP response. :param response: HTTP response from the 'jwks_uri' or 'signed_jwks_uri' endpoint :return: response parsed as JSON or None """ # Check if the content type is the right one. try: if response.headers["Content-Type"] == 'application/json': logger.debug( "Loaded JWKS: %s from %s" % (response.text, self.source)) try: return json.loads(response.text) except ValueError: return None elif response.headers["Content-Type"] == 'application/jwt': logger.debug( "Signed JWKS: %s from %s" % (response.text, self.source))
python
{ "resource": "" }
q279007
dump
test
def dump(filename, dbname, username=None, password=None, host=None, port=None, tempdir='/tmp', pg_dump_path='pg_dump', format='p'): """Performs a pg_dump backup. It runs with the current systemuser's privileges, unless you specify username and password. By default pg_dump connects to the value given in the PGHOST environment variable. You can either specify "hostname" and "port" or a socket path. pg_dump expects the pg_dump-utility to be on $PATCH. Should that not be case you are allowed to specify a custom location with "pg_dump_path" Format is p (plain / default), c = custom, d = directory, t=tar returns statuscode and shelloutput """ filepath = os.path.join(tempdir, filename)
python
{ "resource": "" }
q279008
db_list
test
def db_list(username=None, password=None, host=None, port=None, maintain_db='postgres'): "returns a list of all databases on this server" conn = _connection(username=username, password=password, host=host, port=port, db=maintain_db) cur
python
{ "resource": "" }
q279009
Tigre._get_local_files
test
def _get_local_files(self, path): """Returns a dictionary of all the files under a path.""" if not path: raise ValueError("No path specified") files = defaultdict(lambda: None) path_len = len(path) + 1 for root, dirs, filenames in os.walk(path):
python
{ "resource": "" }
q279010
Tigre.sync_folder
test
def sync_folder(self, path, bucket): """Syncs a local directory with an S3 bucket. Currently does not delete files from S3 that are not in the local directory. path: The path to the directory to sync to S3 bucket: The name of the bucket on S3 """ bucket = self.conn.get_bucket(bucket) local_files = self._get_local_files(path) s3_files = self._get_s3_files(bucket) for filename, hash in local_files.iteritems(): s3_key = s3_files[filename] if s3_key is None:
python
{ "resource": "" }
q279011
tokens_required
test
def tokens_required(service_list): """ Ensure the user has the necessary tokens for the specified services """ def decorator(func): @wraps(func) def inner(request, *args, **kwargs): for service in service_list: if service
python
{ "resource": "" }
q279012
login
test
def login(request, template_name='ci/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm): """ Displays the login form and handles the login action. """ redirect_to = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, '')) if request.method == "POST": form = authentication_form(request, data=request.POST) if form.is_valid(): # Ensure the user-originating redirection url is safe. if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL) # Okay, security check complete. Get the user object from auth api. user = form.get_user() request.session['user_token'] = user["token"] request.session['user_email'] = user["email"] request.session['user_permissions'] = user["permissions"] request.session['user_id'] = user["id"] request.session['user_list'] = user["user_list"] if not settings.HIDE_DASHBOARDS: # Set user dashboards because they are slow to change dashboards = ciApi.get_user_dashboards(user["id"]) dashboard_list = list(dashboards['results']) if len(dashboard_list) > 0: request.session['user_dashboards'] = \ dashboard_list[0]["dashboards"] request.session['user_default_dashboard'] = \ dashboard_list[0]["default_dashboard"]["id"] else: request.session['user_dashboards'] = [] request.session['user_default_dashboard'] = None # Get the user access tokens too and format for easy access
python
{ "resource": "" }
q279013
build
test
def build(cli, path, package): """Build CLI dynamically based on the package structure. """ for _, name, ispkg in iter_modules(path): module = import_module(f'.{name}', package) if ispkg: build(cli.group(name)(module.group),
python
{ "resource": "" }
q279014
Fridge.readonly
test
def readonly(cls, *args, **kwargs): """ Return an already closed read-only instance of Fridge. Arguments are the same as for the constructor.
python
{ "resource": "" }
q279015
Fridge.load
test
def load(self): """ Force reloading the data from the file. All data in the in-memory dictionary is discarded. This method is called automatically by the constructor, normally you don't need to call it.
python
{ "resource": "" }
q279016
self_sign_jwks
test
def self_sign_jwks(keyjar, iss, kid='', lifetime=3600): """ Create a signed JWT containing a JWKS. The JWT is signed by one of the keys in the JWKS. :param keyjar: A KeyJar instance with at least one private signing key :param iss: issuer of the JWT, should be the owner of the keys :param kid: A key ID if a special key should be used otherwise one is picked at random.
python
{ "resource": "" }
q279017
request_signed_by_signing_keys
test
def request_signed_by_signing_keys(keyjar, msreq, iss, lifetime, kid=''): """ A metadata statement signing request with 'signing_keys' signed by one of the keys in 'signing_keys'. :param keyjar: A KeyJar instance with the private signing key :param msreq: Metadata statement signing request. A MetadataStatement
python
{ "resource": "" }
q279018
library
test
def library(func): """ A decorator for providing a unittest with a library and have it called only once. """ @wraps(func) def wrapped(*args, **kwargs):
python
{ "resource": "" }
q279019
descovery
test
def descovery(testdir): """Descover and load greencard tests.""" from os.path import join, exists, isdir, splitext, basename, sep if not testdir or not exists(testdir) or not isdir(testdir): return None from os import walk import fnmatch import imp for root, _, filenames in walk(testdir):
python
{ "resource": "" }
q279020
main
test
def main(clargs=None): """Command line entry point.""" from argparse import ArgumentParser from librarian.library import Library import sys parser = ArgumentParser( description="A test runner for each card in a librarian library.") parser.add_argument("library", help="Library database") parser.add_argument("-t", "--tests", default="test/", help="Test directory")
python
{ "resource": "" }
q279021
letter_score
test
def letter_score(letter): """Returns the Scrabble score of a letter. Args: letter: a single character string Raises: TypeError if a non-Scrabble character is supplied """ score_map = { 1: ["a", "e", "i", "o", "u", "l", "n", "r", "s", "t"], 2: ["d", "g"], 3: ["b", "c", "m", "p"], 4: ["f", "h", "v", "w", "y"], 5: ["k"], 8: ["j", "x"],
python
{ "resource": "" }
q279022
word_score
test
def word_score(word, input_letters, questions=0): """Checks the Scrabble score of a single word. Args: word: a string to check the Scrabble score of input_letters: the letters in our rack questions: integer of the tiles already on the board to build on Returns: an integer Scrabble score amount for the word """ score = 0 bingo = 0 filled_by_blanks = [] rack = list(input_letters) # make a copy to speed up find_anagrams() for letter in word: if letter in rack: bingo += 1 score += letter_score(letter) rack.remove(letter)
python
{ "resource": "" }
q279023
word_list
test
def word_list(sowpods=False, start="", end=""): """Opens the word list file. Args: sowpods: a boolean to declare using the sowpods list or TWL (default) start: a string of starting characters to find anagrams based on end: a string of ending characters to find anagrams based on Yeilds: a word at a time out of 178691 words for TWL, 267751 for sowpods. Much less if either start or end are used (filtering is applied here) """ location = os.path.join( os.path.dirname(os.path.realpath(__file__)), "wordlists", ) if sowpods: filename = "sowpods.txt" else: filename = "twl.txt"
python
{ "resource": "" }
q279024
valid_scrabble_word
test
def valid_scrabble_word(word): """Checks if the input word could be played with a full bag of tiles. Returns: True or false """ letters_in_bag = { "a": 9, "b": 2, "c": 2, "d": 4, "e": 12, "f": 2, "g": 3, "h": 2, "i": 9, "j": 1, "k": 1, "l": 4, "m": 2, "n": 6, "o": 8, "p": 2, "q": 1, "r": 6, "s": 4, "t": 6, "u": 4, "v": 2, "w": 2, "x": 1, "y": 2, "z": 1, "_": 2, }
python
{ "resource": "" }
q279025
main
test
def main(args): """docstring for main""" try: args.query = ' '.join(args.query).replace('?', '') so = SOSearch(args.query, args.tags) result = so.first_q().best_answer.code if result != None: print result
python
{ "resource": "" }
q279026
cli_run
test
def cli_run(): """docstring for argparse""" parser = argparse.ArgumentParser(description='Stupidly simple code answers from StackOverflow')
python
{ "resource": "" }
q279027
JSONAMPDialectReceiver.stringReceived
test
def stringReceived(self, string): """Handle a JSON AMP dialect request. First, the JSON is parsed. Then, all JSON dialect specific values in the request are turned into the correct objects. Then, finds the correct responder function, calls it, and
python
{ "resource": "" }
q279028
JSONAMPDialectReceiver._getCommandAndResponder
test
def _getCommandAndResponder(self, commandName): """Gets the command class and matching responder function for the given command name. """ # DISGUSTING IMPLEMENTATION DETAIL EXPLOITING
python
{ "resource": "" }
q279029
JSONAMPDialectReceiver._parseRequestValues
test
def _parseRequestValues(self, request, command): """Parses all the values in the request that are in a form specific to the JSON AMP dialect. """ for key, ampType in command.arguments:
python
{ "resource": "" }
q279030
JSONAMPDialectReceiver._runResponder
test
def _runResponder(self, responder, request, command, identifier): """Run the responser function. If it succeeds, add the _answer key. If it fails with an error known to the command, serialize the error. """ d = defer.maybeDeferred(responder, **request) def _addIdentifier(response): """Return the response with an ``_answer`` key. """ response["_answer"] = identifier return response def _serializeFailure(failure): """
python
{ "resource": "" }
q279031
JSONAMPDialectReceiver._writeResponse
test
def _writeResponse(self, response): """ Serializes the response to JSON, and writes it to the transport. """
python
{ "resource": "" }
q279032
JSONAMPDialectReceiver.connectionLost
test
def connectionLost(self, reason): """ Tells the box receiver to stop receiving boxes.
python
{ "resource": "" }
q279033
JSONAMPDialectFactory.buildProtocol
test
def buildProtocol(self, addr): """ Builds a bridge and associates it with an AMP protocol instance. """
python
{ "resource": "" }
q279034
jwks_to_keyjar
test
def jwks_to_keyjar(jwks, iss=''): """ Convert a JWKS to a KeyJar instance. :param jwks: String representation of a JWKS :return: A :py:class:`oidcmsg.key_jar.KeyJar` instance """ if not isinstance(jwks, dict): try: jwks
python
{ "resource": "" }
q279035
JWKSBundle.loads
test
def loads(self, jstr): """ Upload a bundle from an unsigned JSON document :param jstr: A bundle as a dictionary or a JSON document """ if isinstance(jstr, dict): _info = jstr else: _info = json.loads(jstr) for iss, jwks in _info.items(): kj = KeyJar() if isinstance(jwks, dict):
python
{ "resource": "" }
q279036
nova_process
test
def nova_process(body, message): """ This function deal with the nova notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = nova_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279037
cinder_process
test
def cinder_process(body, message): """ This function deal with the cinder notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = cinder_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279038
neutron_process
test
def neutron_process(body, message): """ This function deal with the neutron notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = neutron_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279039
glance_process
test
def glance_process(body, message): """ This function deal with the glance notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = glance_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279040
swift_process
test
def swift_process(body, message): """ This function deal with the swift notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = swift_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279041
keystone_process
test
def keystone_process(body, message): """ This function deal with the keystone notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = keystone_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279042
heat_process
test
def heat_process(body, message): """ This function deal with the heat notification. First, find process from customer_process that not include wildcard. if not find from customer_process, then find process from customer_process_wildcard. if not find from customer_process_wildcard, then use ternya default process. :param body: dict of openstack notification. :param message: kombu Message class :return: """ event_type = body['event_type'] process = heat_customer_process.get(event_type) if process is not None: process(body, message) else: matched = False process_wildcard = None
python
{ "resource": "" }
q279043
App.serve
test
def serve(self, server=None): """Serve app using wsgiref or provided server. Args: - server (callable): An callable """ if server is None: from wsgiref.simple_server import make_server server = lambda app: make_server('', 8000, app).serve_forever()
python
{ "resource": "" }
q279044
pout
test
def pout(msg, log=None): """Print 'msg' to stdout, and option 'log' at info level.""" _print(msg,
python
{ "resource": "" }
q279045
perr
test
def perr(msg, log=None): """Print 'msg' to stderr, and option 'log' at info level.""" _print(msg,
python
{ "resource": "" }
q279046
register
test
def register(CommandSubClass): """A class decorator for Command classes to register in the default set.""" name = CommandSubClass.name() if name in Command._all_commands: raise ValueError("Command
python
{ "resource": "" }
q279047
Command.register
test
def register(Class, CommandSubClass): """A class decorator for Command classes to register.""" for name in [CommandSubClass.name()] + CommandSubClass.aliases():
python
{ "resource": "" }
q279048
ConstrainedArgument.toString
test
def toString(self, value): """ If all of the constraints are satisfied with the given value, defers to the composed AMP argument's ``toString`` method.
python
{ "resource": "" }
q279049
ConstrainedArgument.fromString
test
def fromString(self, string): """ Converts the string to a value using the composed AMP argument, then
python
{ "resource": "" }
q279050
_updateCompleterDict
test
def _updateCompleterDict(completers, cdict, regex=None): """Merges ``cdict`` into ``completers``. In the event that a key in cdict already exists in the completers dict a ValueError is raised iff ``regex`` false'y. If a regex str is provided it and the duplicate key are updated to be unique, and the updated regex is returned. """ for key in cdict: if key in completers and not regex: raise ValueError(f"Duplicate completion key: {key}")
python
{ "resource": "" }
q279051
Ternya.work
test
def work(self): """ Start ternya work. First, import customer's service modules. Second, init openstack mq.
python
{ "resource": "" }
q279052
Ternya.init_mq
test
def init_mq(self): """Init connection and consumer with openstack mq.""" mq = self.init_connection()
python
{ "resource": "" }
q279053
Ternya.init_modules
test
def init_modules(self): """Import customer's service modules.""" if not self.config: raise ValueError("please read your config file.") log.debug("begin to import customer's service modules.")
python
{ "resource": "" }
q279054
Ternya.init_nova_consumer
test
def init_nova_consumer(self, mq): """ Init openstack nova mq 1. Check if enable listening nova notification 2. Create consumer :param mq: class ternya.mq.MQ """ if not self.enable_component_notification(Openstack.Nova): log.debug("disable listening nova notification") return
python
{ "resource": "" }
q279055
Ternya.init_cinder_consumer
test
def init_cinder_consumer(self, mq): """ Init openstack cinder mq 1. Check if enable listening cinder notification 2. Create consumer :param mq: class ternya.mq.MQ """ if not self.enable_component_notification(Openstack.Cinder): log.debug("disable listening cinder notification") return
python
{ "resource": "" }
q279056
Ternya.init_neutron_consumer
test
def init_neutron_consumer(self, mq): """ Init openstack neutron mq 1. Check if enable listening neutron notification 2. Create consumer :param mq: class ternya.mq.MQ """ if not self.enable_component_notification(Openstack.Neutron): log.debug("disable listening neutron notification") return
python
{ "resource": "" }
q279057
Ternya.init_glance_consumer
test
def init_glance_consumer(self, mq): """ Init openstack glance mq 1. Check if enable listening glance notification 2. Create consumer :param mq: class ternya.mq.MQ """ if not self.enable_component_notification(Openstack.Glance): log.debug("disable listening glance notification") return
python
{ "resource": "" }
q279058
Ternya.init_heat_consumer
test
def init_heat_consumer(self, mq): """ Init openstack heat mq 1. Check if enable listening heat notification 2. Create consumer :param mq: class ternya.mq.MQ """ if not self.enable_component_notification(Openstack.Heat): log.debug("disable listening heat notification") return
python
{ "resource": "" }
q279059
Ternya.enable_component_notification
test
def enable_component_notification(self, openstack_component): """ Check if customer enable openstack component notification. :param openstack_component: Openstack component type. """ openstack_component_mapping = { Openstack.Nova: self.config.listen_nova_notification, Openstack.Cinder: self.config.listen_cinder_notification, Openstack.Neutron: self.config.listen_neutron_notification,
python
{ "resource": "" }
q279060
music_info
test
def music_info(songid): """ Get music info from baidu music api """ if isinstance(songid, list): songid = ','.join(songid) data = { "hq": 1, "songIds": songid } res = requests.post(MUSIC_INFO_URL, data=data) info = res.json() music_data = info["data"] songs = [] for song in music_data["songList"]: song_link, size =
python
{ "resource": "" }
q279061
download_music
test
def download_music(song, thread_num=4): """ process for downing music with multiple threads """ filename = "{}.mp3".format(song["name"]) if os.path.exists(filename): os.remove(filename) part = int(song["size"] / thread_num) if part <= 1024: thread_num = 1 _id = uuid.uuid4().hex logger.info("downloading '{}'...".format(song["name"])) threads = [] for i in range(thread_num): if i == thread_num - 1: end = '' else: end = (i + 1) * part - 1 thread = Worker((i * part, end),
python
{ "resource": "" }
q279062
Machine.execute
test
def execute(self, globals_=None, _locals=None): """ Execute a code object The inputs and behavior of this function should match those of eval_ and exec_. .. _eval: https://docs.python.org/3/library/functions.html?highlight=eval#eval .. _exec: https://docs.python.org/3/library/functions.html?highlight=exec#exec .. note:: Need to figure out how the internals of this function must change for ``eval`` or ``exec``. :param code: a python code object :param globals_: optional globals dictionary :param _locals: optional locals dictionary """
python
{ "resource": "" }
q279063
Machine.load_name
test
def load_name(self, name): """ Implementation of the LOAD_NAME operation """ if name in self.globals_: return self.globals_[name] b = self.globals_['__builtins__']
python
{ "resource": "" }
q279064
Machine.call_function
test
def call_function(self, c, i): """ Implement the CALL_FUNCTION_ operation. .. _CALL_FUNCTION: https://docs.python.org/3/library/dis.html#opcode-CALL_FUNCTION """ callable_ = self.__stack[-1-i.arg] args = tuple(self.__stack[len(self.__stack) - i.arg:]) self._print('call function') self._print('\tfunction ', callable_) self._print('\ti.arg ', i.arg) self._print('\targs ', args) self.call_callbacks('CALL_FUNCTION', callable_, *args) if isinstance(callable_, FunctionType): ret = callable_(*args)
python
{ "resource": "" }
q279065
dump
test
def dump(filename, dbname, username=None, password=None, host=None, port=None, tempdir='/tmp', mysqldump_path='mysqldump'): """Perfoms a mysqldump backup. Create a database dump for the given database. returns statuscode and shelloutput """ filepath = os.path.join(tempdir, filename) cmd = mysqldump_path cmd += ' --result-file=' + os.path.join(tempdir, filename) if username:
python
{ "resource": "" }
q279066
render_ditaa
test
def render_ditaa(self, code, options, prefix='ditaa'): """Render ditaa code into a PNG output file.""" hashkey = code.encode('utf-8') + str(options) + \ str(self.builder.config.ditaa) + \ str(self.builder.config.ditaa_args) infname = '%s-%s.%s' % (prefix, sha(hashkey).hexdigest(), "ditaa") outfname = '%s-%s.%s' % (prefix, sha(hashkey).hexdigest(), "png") inrelfn = posixpath.join(self.builder.imgpath, infname) infullfn = path.join(self.builder.outdir, '_images', infname) outrelfn = posixpath.join(self.builder.imgpath, outfname) outfullfn = path.join(self.builder.outdir, '_images', outfname) if path.isfile(outfullfn): return outrelfn, outfullfn ensuredir(path.dirname(outfullfn)) # ditaa expects UTF-8 by default if isinstance(code, unicode): code = code.encode('utf-8') ditaa_args = [self.builder.config.ditaa] ditaa_args.extend(self.builder.config.ditaa_args) ditaa_args.extend(options) ditaa_args.extend( [infullfn] ) ditaa_args.extend( [outfullfn] ) f = open(infullfn, 'w') f.write(code) f.close() try: self.builder.warn(ditaa_args) p = Popen(ditaa_args, stdout=PIPE, stdin=PIPE, stderr=PIPE) except OSError, err: if err.errno != ENOENT: # No such file or directory raise self.builder.warn('ditaa command %r cannot be run (needed for ditaa '
python
{ "resource": "" }
q279067
Application._atexit
test
def _atexit(self): """Invoked in the 'finally' block of Application.run."""
python
{ "resource": "" }
q279068
Application.run
test
def run(self, args_list=None): """Run Application.main and exits with the return value.""" self.log.debug("Application.run: {args_list}".format(**locals())) retval = None try: retval = self._run(args_list=args_list) except KeyboardInterrupt: self.log.verbose("Interrupted") # pragma: nocover except SystemExit as exit: self.log.verbose("Exited") retval = exit.code except Exception: print("Uncaught exception", file=sys.stderr) traceback.print_exc()
python
{ "resource": "" }
q279069
cd
test
def cd(path): """Context manager that changes to directory `path` and return to CWD when exited. """ old_path = os.getcwd()
python
{ "resource": "" }
q279070
copytree
test
def copytree(src, dst, symlinks=True): """ Modified from shutil.copytree docs code sample, merges files rather than requiring dst to not exist. """ from shutil import copy2, Error, copystat names = os.listdir(src) if not Path(dst).exists(): os.makedirs(dst) errors = [] for name in names: srcname = os.path.join(src, name) dstname = os.path.join(dst, name) try: if symlinks and os.path.islink(srcname): linkto = os.readlink(srcname)
python
{ "resource": "" }
q279071
debugger
test
def debugger(): """If called in the context of an exception, calls post_mortem; otherwise set_trace. ``ipdb`` is preferred over ``pdb`` if installed. """ e, m, tb
python
{ "resource": "" }
q279072
FileSystem.get_mtime
test
def get_mtime(fname): """ Find the time this file was last modified. :param fname: File name :return: The last time the file was modified. """ try: mtime = os.stat(fname).st_mtime_ns except OSError:
python
{ "resource": "" }
q279073
FileSystem.is_changed
test
def is_changed(self, item): """ Find out if this item has been modified since last :param item: A key :return: True/False """ fname = os.path.join(self.fdir, item) if os.path.isfile(fname): mtime = self.get_mtime(fname) try: _ftime = self.fmtime[item] except KeyError: # Never been seen before self.fmtime[item] = mtime
python
{ "resource": "" }
q279074
FileSystem.sync
test
def sync(self): """ Goes through the directory and builds a local cache based on the content of the directory. """ if not os.path.isdir(self.fdir): os.makedirs(self.fdir) for f in os.listdir(self.fdir): fname = os.path.join(self.fdir, f) if not os.path.isfile(fname): continue if f in self.fmtime:
python
{ "resource": "" }
q279075
FileSystem.clear
test
def clear(self): """ Completely resets the database. This means that all information in the local cache and on disc will be
python
{ "resource": "" }
q279076
scrape
test
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 =
python
{ "resource": "" }
q279077
Camera.download_image
test
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)
python
{ "resource": "" }
q279078
Camera.has_changed
test
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
python
{ "resource": "" }
q279079
fancy_tag_compiler
test
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:
python
{ "resource": "" }
q279080
SeabornLogger.findCaller
test
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)"
python
{ "resource": "" }
q279081
get_defining_component
test
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]()
python
{ "resource": "" }
q279082
main
test
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",
python
{ "resource": "" }
q279083
SymbolTable.find_symbol
test
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
python
{ "resource": "" }
q279084
is_contained_in
test
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]:
python
{ "resource": "" }
q279085
is_global
test
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
python
{ "resource": "" }
q279086
_get_data_type_name
test
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
python
{ "resource": "" }
q279087
_get_related_attributes
test
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):
python
{ "resource": "" }
q279088
mk_enum
test
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 + '_')
python
{ "resource": "" }
q279089
mk_bridge
test
def mk_bridge(metamodel, s_brg): ''' Create a python function from a BridgePoint bridge. ''' action = s_brg.Action_Semantics_internal label = s_brg.Name
python
{ "resource": "" }
q279090
mk_external_entity
test
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
python
{ "resource": "" }
q279091
mk_function
test
def mk_function(metamodel, s_sync): ''' Create a python function from a BridgePoint function. ''' action = s_sync.Action_Semantics_internal label = s_sync.Name
python
{ "resource": "" }
q279092
mk_constant
test
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
python
{ "resource": "" }
q279093
mk_operation
test
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:
python
{ "resource": "" }
q279094
mk_derived_attribute
test
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
python
{ "resource": "" }
q279095
mk_class
test
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' %
python
{ "resource": "" }
q279096
mk_simple_association
test
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
python
{ "resource": "" }
q279097
mk_linked_association
test
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,
python
{ "resource": "" }
q279098
mk_association
test
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,
python
{ "resource": "" }
q279099
mk_component
test
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)
python
{ "resource": "" }