signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def parse_url(self): | url = urlparse(self.url).path<EOL>url = url.split('<STR_LIT>')[<NUM_LIT:0>]<EOL>if '<STR_LIT::>' in url:<EOL><INDENT>url = url.split('<STR_LIT::>')[<NUM_LIT:1>]<EOL><DEDENT>try:<EOL><INDENT>project, repo = url.split('<STR_LIT:/>')[-<NUM_LIT:2>:]<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ParserError('<STR_LIT>'.format(self.url))<EOL><DEDENT>return project, repo<EOL> | Parse a git/ssh/http(s) url. | f15618:c1:m1 |
def __getattr__(self, name): | return self.data[name].format(**self.data)<EOL> | Return formatted string from :attr:`format`. | f15620:c1:m1 |
@property<EOL><INDENT>def app(self):<DEDENT> | logging.warning('<STR_LIT>')<EOL>return self.app_name()<EOL> | Return the generated app name. | f15620:c1:m2 |
@property<EOL><INDENT>def project(self):<DEDENT> | return self.data['<STR_LIT>']<EOL> | Return the project property. | f15620:c1:m3 |
@property<EOL><INDENT>def repo(self):<DEDENT> | return self.data['<STR_LIT>']<EOL> | Return the repo property. | f15620:c1:m4 |
@property<EOL><INDENT>def env(self):<DEDENT> | return self.data['<STR_LIT>']<EOL> | Return the env property. | f15620:c1:m5 |
def app_name(self): | app = self.format['<STR_LIT>'].format(**self.data)<EOL>return app<EOL> | Generate application name. | f15620:c1:m6 |
def dns_elb(self): | dns = self.format['<STR_LIT>'].format(**self.data)<EOL>return dns<EOL> | Generate elb dns domain. | f15620:c1:m7 |
def dns_elb_region(self): | dns = self.format['<STR_LIT>'].format(**self.data)<EOL>return dns<EOL> | Generate dns domain with region. | f15620:c1:m8 |
def dns_global(self): | dns = self.format['<STR_LIT>'].format(**self.data)<EOL>return dns<EOL> | Generate dns global domain with no region. | f15620:c1:m9 |
def dns_region(self): | dns = self.format['<STR_LIT>'].format(**self.data)<EOL>return dns<EOL> | Generate region specific DNS. | f15620:c1:m10 |
def dns_instance(self): | instance = self.format['<STR_LIT>'].format(**self.data)<EOL>return instance<EOL> | Generate dns instance. | f15620:c1:m11 |
def dns(self): | dns = {<EOL>'<STR_LIT>': self.dns_elb(),<EOL>'<STR_LIT>': self.dns_elb_region(),<EOL>'<STR_LIT>': self.dns_global(),<EOL>'<STR_LIT>': self.dns_region(),<EOL>'<STR_LIT>': self.dns_instance(),<EOL>}<EOL>return dns<EOL> | DNS details. | f15620:c1:m12 |
def s3_app_bucket(self, include_region=False): | if include_region:<EOL><INDENT>s3_app_bucket = self.format['<STR_LIT>'].format(**self.data)<EOL><DEDENT>else:<EOL><INDENT>s3_app_bucket = self.format['<STR_LIT>'].format(**self.data)<EOL><DEDENT>return s3_app_bucket<EOL> | Generate s3 application bucket name.
Args:
include_region (bool): Include region in the name generation. | f15620:c1:m13 |
def shared_s3_app_bucket(self, include_region=False): | if include_region:<EOL><INDENT>shared_s3_app_bucket = self.format['<STR_LIT>'].format(**self.data)<EOL><DEDENT>else:<EOL><INDENT>shared_s3_app_bucket = self.format['<STR_LIT>'].format(**self.data)<EOL><DEDENT>return shared_s3_app_bucket<EOL> | Generate shared s3 application bucket name.
Args:
include_region (bool): Include region in the name generation. | f15620:c1:m14 |
def iam(self): | iam = {<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT:user>': self.format['<STR_LIT>'].format(**self.data),<EOL>'<STR_LIT>': self.format['<STR_LIT>'].format(**self.data),<EOL>}<EOL>return iam<EOL> | Generate iam details. | f15620:c1:m15 |
def archaius(self): | bucket = self.format['<STR_LIT>'].format(**self.data)<EOL>path = self.format['<STR_LIT>'].format(**self.data)<EOL>archaius_name = self.format['<STR_LIT>'].format(**self.data)<EOL>archaius = {'<STR_LIT>': archaius_name, '<STR_LIT>': bucket, '<STR_LIT:path>': path}<EOL>return archaius<EOL> | Generate archaius bucket path. | f15620:c1:m16 |
def jenkins(self): | job_name = self.format['<STR_LIT>'].format(**self.data)<EOL>job = {'<STR_LIT:name>': job_name}<EOL>return job<EOL> | Generate jenkins job details. | f15620:c1:m17 |
def gitlab(self): | main_name = self.format['<STR_LIT>'].format(**self.data)<EOL>qe_name = self.format['<STR_LIT>'].format(**self.data)<EOL>config_name = self.format['<STR_LIT>'].format(**self.data)<EOL>git = {<EOL>'<STR_LIT>': config_name,<EOL>'<STR_LIT>': main_name,<EOL>'<STR_LIT>': qe_name,<EOL>}<EOL>return git<EOL> | Generate gitlab details. | f15620:c1:m18 |
def apigateway(self): | domain = self.format['<STR_LIT>'].format(**self.data)<EOL>return {<EOL>'<STR_LIT>': domain,<EOL>}<EOL> | Generate apigateway details. | f15620:c1:m19 |
def get_formats(self): | return self.config<EOL> | Return overlaid configurations. | f15621:c0:m1 |
def __init__(self, request: Request): | self.request = request<EOL> | Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object | f15643:c0:m0 |
def before(self): | if not self.request.user():<EOL><INDENT>self.request.redirect_to('<STR_LIT>')<EOL><DEDENT> | Run This Middleware Before The Route Executes. | f15643:c0:m1 |
def after(self): | pass<EOL> | Run This Middleware After The Route Executes. | f15643:c0:m2 |
def __init__(self, request: Request): | self.request = request<EOL> | Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object. | f15644:c0:m0 |
def before(self): | self.load_user()<EOL>return self.request<EOL> | Run This Middleware Before The Route Executes. | f15644:c0:m1 |
def after(self): | pass<EOL> | Run This Middleware After The Route Executes. | f15644:c0:m2 |
def load_user(self): | self.request.set_user(Auth(self.request).user())<EOL> | Load user into the request.
Arguments:
request {masonite.request.Request} -- The Masonite request object. | f15644:c0:m3 |
def __init__(self, request: Request): | self.request = request<EOL> | Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object | f15645:c0:m0 |
def before(self): | user = self.request.user()<EOL>if user and user.verified_at is None:<EOL><INDENT>self.request.redirect('<STR_LIT>')<EOL><DEDENT> | Run This Middleware Before The Route Executes. | f15645:c0:m1 |
def after(self): | pass<EOL> | Run This Middleware After The Route Executes. | f15645:c0:m2 |
def show(self, view: View, request: Request): | return view.render('<STR_LIT>', {<EOL>'<STR_LIT>': request.app().make('<STR_LIT>')<EOL>})<EOL> | Show the welcome page.
Arguments:
view {masonite.view.View} -- The Masonite view class.
Application {config.application} -- The application config module.
Returns:
masonite.view.View -- The Masonite view class. | f15646:c0:m0 |
def up(self): | with self.schema.create('<STR_LIT>') as table:<EOL><INDENT>table.increments('<STR_LIT:id>')<EOL>table.string('<STR_LIT:name>')<EOL>table.string('<STR_LIT:email>').unique()<EOL>table.string('<STR_LIT:password>')<EOL>table.string('<STR_LIT>').nullable()<EOL>table.timestamp('<STR_LIT>').nullable()<EOL>table.timestamps()<EOL><DEDENT> | Run the migrations. | f15649:c0:m0 |
def down(self): | self.schema.drop('<STR_LIT>')<EOL> | Revert the migrations. | f15649:c0:m1 |
def run(self): | self.factory.register(User, self.users_factory)<EOL>self.factory(User, <NUM_LIT:50>).create()<EOL> | Run the database seeds. | f15650:c0:m0 |
def run(self): | self.call(UserTableSeeder)<EOL> | Run the database seeds. | f15651:c0:m0 |
def app(environ, start_response): | from wsgi import container<EOL>"""<STR_LIT>"""<EOL>container.bind('<STR_LIT>', environ)<EOL>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>for provider in container.make('<STR_LIT>'):<EOL><INDENT>container.resolve(provider.boot)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>container.make('<STR_LIT>').load_exception(e)<EOL><DEDENT>"""<STR_LIT>"""<EOL>start_response(container.make('<STR_LIT>').get_status_code(),<EOL>container.make('<STR_LIT>').get_and_reset_headers())<EOL>"""<STR_LIT>"""<EOL>return iter([bytes(container.make('<STR_LIT>'), '<STR_LIT:utf-8>')])<EOL> | The WSGI Application Server.
Arguments:
environ {dict} -- The WSGI environ dictionary
start_response {WSGI callable}
Returns:
WSGI Response | f15654:m0 |
def db_for_read(self, model, **hints): | if model._meta.app_label == '<STR_LIT>':<EOL><INDENT>return DUAS_DB_ROUTE_PREFIX<EOL><DEDENT>return None<EOL> | Attempts to read auth models go to duashttp. | f15658:c0:m0 |
def db_for_write(self, model, **hints): | if model._meta.app_label == '<STR_LIT>':<EOL><INDENT>if not DUAS_ENABLE_DB_WRITE:<EOL><INDENT>raise ImproperlyConfigured(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>return DUAS_DB_ROUTE_PREFIX<EOL><DEDENT>return None<EOL> | Attempts to write auth models go to duashttp. | f15658:c0:m1 |
def allow_relation(self, obj1, obj2, **hints): | if obj1._meta.app_label == '<STR_LIT>' orobj2._meta.app_label == '<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>return None<EOL> | Allow relations if a model in the auth app is involved. | f15658:c0:m2 |
def allow_migrate(self, db, model): | if db == DUAS_DB_ROUTE_PREFIX:<EOL><INDENT>return model._meta.app_label == '<STR_LIT>'<EOL><DEDENT>elif model._meta.app_label == '<STR_LIT>':<EOL><INDENT>return False<EOL><DEDENT>return None<EOL> | Make sure the auth app only appears in the 'duashttp'
database. | f15658:c0:m3 |
def get_guid(self): | return int('<STR_LIT>' % self.guid, <NUM_LIT:2>)<EOL> | gives int guid number instead of 01010.. sequence
:rtype: int
:return: guid | f15660:c2:m1 |
def get_digest(self): | a, b = struct.unpack('<STR_LIT>', self.digest)<EOL>return (a << <NUM_LIT:64>) | b<EOL> | return int uuid number for digest
:rtype: int
:return: digest | f15660:c5:m4 |
def get_blob_hash(self, h=hashlib.md5): | assert callable(h)<EOL>return h(self.get_blob_data())<EOL> | get hash instance of blob content
:param h: callable hash generator
:type h: builtin_function_or_method
:rtype: _hashlib.HASH
:return: hash instance | f15660:c5:m5 |
def get_blob_data(self, tag_target='<STR_LIT>', force=False): | if hasattr(self, '<STR_LIT>') and not force:<EOL><INDENT>return self._blob_data<EOL><DEDENT>if six.PY2:<EOL><INDENT>self._blob_data = six.binary_type('<STR_LIT>')<EOL><DEDENT>elif six.PY3:<EOL><INDENT>self._blob_data = six.binary_type('<STR_LIT>', encoding='<STR_LIT:ascii>')<EOL><DEDENT>asset_contents = self.contents.filter(tag=tag_target)<EOL>for asset_content in asset_contents:<EOL><INDENT>blobs = asset_content.stream.get_blobs()<EOL>for blob in blobs:<EOL><INDENT>self._blob_data += six.binary_type(blob.data)<EOL><DEDENT><DEDENT>return self._blob_data<EOL> | get asset version content using pg large object streams
:param bool force: False by default, forces get content from database
instead of using cached value
:rtype: str
:return: content in raw format | f15660:c5:m6 |
@action(methods=['<STR_LIT:GET>', ])<EOL><INDENT>def blob(self, request, pk=None):<DEDENT> | obj = self.get_object_or_none()<EOL>if obj:<EOL><INDENT>blob = obj.get_blob_data()<EOL>content_type = '<STR_LIT>'<EOL>response = HttpResponse(blob, content_type=content_type,<EOL>status=status.HTTP_200_OK)<EOL>response['<STR_LIT>'] = (<EOL>'<STR_LIT>' % obj.name<EOL>)<EOL>return response<EOL><DEDENT>return HttpResponse('<STR_LIT>', status=status.HTTP_404_NOT_FOUND,<EOL>content_type='<STR_LIT:application/json>')<EOL> | fetch large object from pg and gives it back to user via HTTP 1.1
request
:param request: django request instance
:param pk: requested resource primary key
:rtype: django.http.HttpResponse
:rtype: HttpResponse
:return: file with its filename stored in database | f15662:c0:m0 |
def freeze(): | installations = {}<EOL>for dist in get_installed_distributions():<EOL><INDENT>req = pip.FrozenRequirement.from_dist(dist, [], find_tags=False)<EOL>installations[req.name] = req<EOL><DEDENT>return [str(installation).rstrip() for installation in<EOL>sorted(installations.values(), key=lambda x: x.name.lower())]<EOL> | Show arguments to require() to recreate what has been installed | f15664:m0 |
def require(*args, **kwargs): | <EOL>if not args and not kwargs:<EOL><INDENT>return freeze()<EOL><DEDENT>requirements = list(args)<EOL>extra = ['<STR_LIT>'.format(kw, kwargs[kw]) for kw in kwargs]<EOL>requirements.extend(extra)<EOL>args = ['<STR_LIT>', '<STR_LIT>']<EOL>args.extend(requirements)<EOL>pip.main(args)<EOL> | Install a set of packages using pip
This is designed to be an interface for IPython notebooks that
replicates the requirements.txt pip format. This lets notebooks
specify which versions of packages they need inside the notebook
itself.
This function is the general-purpose interface that lets
the caller specify any version string for any package. | f15664:m1 |
def color(txt, color=WHITE, bold=True, bgcolor=None, inverse=False): | boldtxt = "<STR_LIT:0>"<EOL>if bold:<EOL><INDENT>boldtxt = "<STR_LIT:1>"<EOL><DEDENT>colortxt = "<STR_LIT>"<EOL>if color is not None:<EOL><INDENT>colortxt = "<STR_LIT>".format(<NUM_LIT:30> + color)<EOL><DEDENT>bgcolortxt = "<STR_LIT>"<EOL>if bgcolor is not None:<EOL><INDENT>bgcolortxt = "<STR_LIT>".format(<NUM_LIT> + bgcolor)<EOL><DEDENT>inversetxt = "<STR_LIT>"<EOL>if inverse:<EOL><INDENT>inversetxt = "<STR_LIT>"<EOL><DEDENT>return u"<STR_LIT>".format(boldtxt, colortxt, bgcolortxt, inversetxt, txt)<EOL> | Construct string to use ANSI color escapes around text | f15667:m0 |
def table_of_result(self, result): | rows = []<EOL>def add(label, lst, style):<EOL><INDENT>for test, backtrace in lst:<EOL><INDENT>rows.append([label, result.getDescription(test), style])<EOL><DEDENT><DEDENT>add(CHECK, result.successes, u'<STR_LIT>')<EOL>add(CROSS, result.failures, u'<STR_LIT>')<EOL>add(HEAVY_CROSS, result.errors, u'<STR_LIT>')<EOL>add(SKIP, result.skipped, u'<STR_LIT>')<EOL>add(CHECK, result.expectedFailures, u'<STR_LIT>')<EOL>add(CROSS, result.unexpectedSuccesses, u'<STR_LIT>')<EOL>bd = u'<STR_LIT:\n>'.join([u'<STR_LIT>'.format(row[<NUM_LIT:2>], row[<NUM_LIT:0>], row[<NUM_LIT:1>]) for row in rows])<EOL>return u'<STR_LIT:{}>'.format(bd)<EOL> | Convert unittest Result object into HTML table | f15667:c3:m1 |
def summary_of_result(self, result, timeTaken): | run = result.testsRun<EOL>expectedFails = unexpectedSuccesses = skipped = <NUM_LIT:0><EOL>try:<EOL><INDENT>results = map(len, (result.expectedFailures,<EOL>result.unexpectedSuccesses,<EOL>result.skipped))<EOL>expectedFails, unexpectedSuccesses, skipped = results<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>infos = []<EOL>if not result.wasSuccessful():<EOL><INDENT>failed, errored = map(len, (result.failures, result.errors))<EOL>if failed:<EOL><INDENT>infos.append(u"<STR_LIT>" % failed)<EOL><DEDENT>if errored:<EOL><INDENT>infos.append(u"<STR_LIT>" % errored)<EOL><DEDENT><DEDENT>if skipped:<EOL><INDENT>infos.append(u"<STR_LIT>" % skipped)<EOL><DEDENT>if expectedFails:<EOL><INDENT>infos.append(u"<STR_LIT>" % expectedFails)<EOL><DEDENT>if unexpectedSuccesses:<EOL><INDENT>infos.append(u"<STR_LIT>" % unexpectedSuccesses)<EOL><DEDENT>msg_txt = u"<STR_LIT>".format(run, run != <NUM_LIT:1> and '<STR_LIT:s>' or '<STR_LIT>')<EOL>info_txt = u'<STR_LIT>'<EOL>if infos:<EOL><INDENT>info_txt = u"<STR_LIT>".format("<STR_LIT:U+002CU+0020>".join(infos))<EOL><DEDENT>time_txt = u"<STR_LIT>".format(timeTaken*<NUM_LIT:1000>)<EOL>result_txt = u"<STR_LIT>".format("<STR_LIT:OK>" if result.wasSuccessful() else "<STR_LIT>")<EOL>class_txt = u"<STR_LIT>" if result.wasSuccessful() else u"<STR_LIT>"<EOL>return u"<STR_LIT>".format(class_txt, msg_txt, info_txt, time_txt, class_txt, result_txt)<EOL> | Formulate paragraph summary line at end | f15667:c3:m2 |
def list_of_errors(self, result): | separator = u'<STR_LIT>' <EOL>res = []<EOL>def describe(style, tag, lst):<EOL><INDENT>for test, err in lst:<EOL><INDENT>headline = u"<STR_LIT>".format(style, tag, result.getDescription(test))<EOL>body = u"<STR_LIT>".format(u'<STR_LIT>', err)<EOL>res.append(separator)<EOL>res.append(headline)<EOL>res.append(body)<EOL><DEDENT><DEDENT>describe(u'<STR_LIT>', u'<STR_LIT>', result.errors)<EOL>describe(u'<STR_LIT>', u'<STR_LIT>', result.failures)<EOL>return u'<STR_LIT:\n>'.join(res)<EOL> | Make list of errors | f15667:c3:m3 |
def get_tape(self, start=<NUM_LIT:0>, end=<NUM_LIT:10>): | self.tape_start = start<EOL>self.tape_end = end<EOL>self.tape_length = end - start<EOL>tmp = '<STR_LIT:\n>'+"<STR_LIT:|>"+str(start)+"<STR_LIT>"<EOL>for i in xrange(len(self.tape[start:end])):<EOL><INDENT>if i == self.cur_cell:<EOL><INDENT>tmp += "<STR_LIT:[>" + str(self.tape[i]) + "<STR_LIT>"<EOL><DEDENT>else: tmp += "<STR_LIT::>" + str(self.tape[i]) + "<STR_LIT>"<EOL><DEDENT>tmp += "<STR_LIT>"+str(end)+"<STR_LIT:|>"<EOL>return tmp<EOL> | Pretty prints the tape values | f15671:c0:m4 |
def authenticate(url, username, password): | <EOL>s = requests.Session()<EOL>data = s.get(url).content<EOL>class LoginParser(HTMLParser):<EOL><INDENT>url = '<STR_LIT>'<EOL>def handle_starttag(self, tag, alist):<EOL><INDENT>attrs = dict(alist)<EOL>if tag == '<STR_LIT>':<EOL><INDENT>self.url = attrs['<STR_LIT:action>']<EOL><DEDENT><DEDENT><DEDENT>loginparser = LoginParser()<EOL>loginparser.feed(data.decode())<EOL>targeturl = '<STR_LIT>' + loginparser.url<EOL>s.headers = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': targeturl}<EOL>form = s.post(targeturl,<EOL>data={'<STR_LIT>': username, '<STR_LIT>': password,<EOL>'<STR_LIT>': '<STR_LIT:1>', '<STR_LIT>': '<STR_LIT>'}).content<EOL>class ShibbolethParser(HTMLParser):<EOL><INDENT>url = '<STR_LIT>'<EOL>to_post = {}<EOL>def handle_starttag(self, tag, alist):<EOL><INDENT>attrs = dict(alist)<EOL>if tag == '<STR_LIT>':<EOL><INDENT>self.url = attrs['<STR_LIT:action>']<EOL><DEDENT>elif tag == '<STR_LIT:input>' and attrs['<STR_LIT:type>'] != '<STR_LIT>':<EOL><INDENT>self.to_post[attrs['<STR_LIT:name>']] = attrs['<STR_LIT:value>']<EOL><DEDENT><DEDENT><DEDENT>parser = ShibbolethParser()<EOL>parser.feed(form.decode())<EOL>s.headers = {'<STR_LIT>': urlparse(url).netloc,<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': targeturl,<EOL>'<STR_LIT>': '<STR_LIT>'}<EOL>s.post(parser.url, data=parser.to_post).content<EOL>return s<EOL> | Queries an asset behind CMU's WebISO wall.
It uses Shibboleth authentication (see: http://dev.e-taxonomy.eu/trac/wiki/ShibbolethProtocol)
Note that you can use this to authenticate stuff beyond just grades! (any CMU service)
Sample usage:
s = authenticate('https://enr-apps.as.cmu.edu/audit/audit', 'wcrichto', '<wcrichto password>')
print s.get('https://enr-apps.as.cmu.edu/audit/audit').content | f15673:m0 |
def get_protractor_params(self): | return {<EOL>'<STR_LIT>': self.live_server_url<EOL>}<EOL> | A hook for adding params that protractor will receive. | f15676:c0:m2 |
def teardown_databases(self, old_config, options): | if len(old_config) > <NUM_LIT:1>:<EOL><INDENT>old_names, mirrors = old_config<EOL><DEDENT>else:<EOL><INDENT>old_names = old_config<EOL><DEDENT>for connection, old_name, destroy in old_names:<EOL><INDENT>if destroy:<EOL><INDENT>connection.creation.destroy_test_db(old_name, options['<STR_LIT>'])<EOL><DEDENT><DEDENT> | Destroys all the non-mirror databases. | f15677:c0:m2 |
def http_construct(args, unknown): | str_http = '<STR_LIT>'<EOL>b_httpSpecd = False<EOL>if '<STR_LIT>' in unknown:<EOL><INDENT>try:<EOL><INDENT>str_httpArg = unknown[unknown.index('<STR_LIT>')+<NUM_LIT:1>]<EOL>unknown.remove('<STR_LIT>')<EOL>unknown.remove(str_httpArg)<EOL><DEDENT>except:<EOL><INDENT>str_httpArg = "<STR_LIT>"<EOL><DEDENT>str_http = '<STR_LIT>' % str_httpArg<EOL>b_httpSpecd = True<EOL><DEDENT>if not b_httpSpecd:<EOL><INDENT>str_serverIP = "<STR_LIT>"<EOL>str_serverPort = '<STR_LIT>'<EOL>try:<EOL><INDENT>if args.b_pman:<EOL><INDENT>str_serverIP = os.environ['<STR_LIT>']<EOL>str_serverPort = os.environ['<STR_LIT>']<EOL><DEDENT>if args.b_pfioh:<EOL><INDENT>str_serverIP = os.environ['<STR_LIT>']<EOL>str_serverPort = os.environ['<STR_LIT>']<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>str_http = '<STR_LIT>' % (str_serverIP, str_serverPort)<EOL><DEDENT>return str_http<EOL> | Construct the --http <arg> from the args/unknown space -- relevant only for 'purl'.
:param args:
:param unknown:
:return: | f15680:m0 |
def zipdir(path, ziph, **kwargs): | str_arcroot = "<STR_LIT>"<EOL>for k, v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT>': str_arcroot = v<EOL><DEDENT>for root, dirs, files in os.walk(path):<EOL><INDENT>for file in files:<EOL><INDENT>str_arcfile = os.path.join(root, file)<EOL>if len(str_arcroot):<EOL><INDENT>str_arcname = str_arcroot.split('<STR_LIT:/>')[-<NUM_LIT:1>] + str_arcfile.split(str_arcroot)[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>str_arcname = str_arcfile<EOL><DEDENT>try:<EOL><INDENT>ziph.write(str_arcfile, arcname = str_arcname)<EOL><DEDENT>except:<EOL><INDENT>print("<STR_LIT>" % str_arcfile)<EOL><DEDENT><DEDENT><DEDENT> | Zip up a directory.
:param path:
:param ziph:
:param kwargs:
:return: | f15684:m0 |
def zip_process(**kwargs): | str_localPath = "<STR_LIT>"<EOL>str_zipFileName = "<STR_LIT>"<EOL>str_action = "<STR_LIT>"<EOL>str_arcroot = "<STR_LIT>"<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT:path>': str_localPath = v<EOL>if k == '<STR_LIT:action>': str_action = v<EOL>if k == '<STR_LIT>': str_zipFileName = v<EOL>if k == '<STR_LIT>': str_arcroot = v<EOL><DEDENT>if str_action == '<STR_LIT>':<EOL><INDENT>str_mode = '<STR_LIT:w>'<EOL>str_zipFileName = '<STR_LIT>' % uuid.uuid4()<EOL><DEDENT>else:<EOL><INDENT>str_mode = '<STR_LIT:r>'<EOL><DEDENT>try:<EOL><INDENT>ziphandler = zipfile.ZipFile(str_zipFileName, str_mode, zipfile.ZIP_DEFLATED)<EOL>if str_mode == '<STR_LIT:w>':<EOL><INDENT>if os.path.isdir(str_localPath):<EOL><INDENT>zipdir(str_localPath, ziphandler, arcroot = str_arcroot)<EOL><DEDENT>else:<EOL><INDENT>if len(str_arcroot):<EOL><INDENT>str_arcname = str_arcroot.split('<STR_LIT:/>')[-<NUM_LIT:1>] + str_localPath.split(str_arcroot)[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>str_arcname = str_localPath<EOL><DEDENT>try:<EOL><INDENT>ziphandler.write(str_localPath, arcname = str_arcname)<EOL><DEDENT>except:<EOL><INDENT>ziphandler.close()<EOL>os.remove(str_zipFileName)<EOL>return {<EOL>'<STR_LIT>': json.dumps({"<STR_LIT>": "<STR_LIT>" % str_localPath}),<EOL>'<STR_LIT:status>': False<EOL>}<EOL><DEDENT><DEDENT><DEDENT>if str_mode == '<STR_LIT:r>':<EOL><INDENT>ziphandler.extractall(str_localPath)<EOL><DEDENT>ziphandler.close()<EOL>str_msg = '<STR_LIT>' % str_action<EOL>b_status = True<EOL><DEDENT>except:<EOL><INDENT>str_msg = '<STR_LIT>' % str_action<EOL>b_status = False<EOL><DEDENT>return {<EOL>'<STR_LIT>': str_msg,<EOL>'<STR_LIT>': str_zipFileName,<EOL>'<STR_LIT:status>': b_status,<EOL>'<STR_LIT:path>': str_localPath,<EOL>'<STR_LIT>': str_mode,<EOL>'<STR_LIT>': "<STR_LIT>".format(os.stat(str_zipFileName).st_size),<EOL>'<STR_LIT>': '<STR_LIT:%s>' % datetime.datetime.now()<EOL>}<EOL> | Process zip operations.
:param kwargs:
:return: | f15684:m1 |
def base64_process(**kwargs): | str_fileToSave = "<STR_LIT>"<EOL>str_fileToRead = "<STR_LIT>"<EOL>str_action = "<STR_LIT>"<EOL>data = None<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT:action>': str_action = v<EOL>if k == '<STR_LIT>': data = v<EOL>if k == '<STR_LIT>': str_fileToRead = v<EOL>if k == '<STR_LIT>': str_fileToSave = v<EOL><DEDENT>if str_action == "<STR_LIT>":<EOL><INDENT>if len(str_fileToRead):<EOL><INDENT>with open(str_fileToRead, '<STR_LIT:rb>') as f:<EOL><INDENT>data = f.read()<EOL>f.close()<EOL><DEDENT><DEDENT>data_b64 = base64.b64encode(data)<EOL>with open(str_fileToSave, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(data_b64)<EOL>f.close()<EOL><DEDENT>return {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': str_fileToSave,<EOL>'<STR_LIT:status>': True<EOL>}<EOL><DEDENT>if str_action == "<STR_LIT>":<EOL><INDENT>bytes_decoded = base64.b64decode(data + "<STR_LIT>")<EOL>with open(str_fileToSave, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(bytes_decoded)<EOL>f.close()<EOL><DEDENT>return {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': str_fileToSave,<EOL>'<STR_LIT:status>': True<EOL>}<EOL><DEDENT> | Process base64 file io | f15684:m2 |
def storage_resolveBasedOnKey(self, *args, **kwargs): | global Gd_internalvar<EOL>d_msg = {<EOL>'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>}<EOL>str_key = "<STR_LIT>"<EOL>b_status = False<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT:key>': str_key = v<EOL><DEDENT>d_msg['<STR_LIT>']['<STR_LIT:key>'] = str_key<EOL>d_ret = self.pullPath_core(d_msg = d_msg)<EOL>return {<EOL>'<STR_LIT:status>': b_status,<EOL>'<STR_LIT:path>': str_internalLocation<EOL>}<EOL> | Call the remote service and ask for the storage location based on the key.
:param args:
:param kwargs:
:return: | f15684:c0:m3 |
def remoteLocation_resolveSimple(self, d_remote): | b_status = False<EOL>str_remotePath = "<STR_LIT>"<EOL>if '<STR_LIT:path>' in d_remote.keys():<EOL><INDENT>str_remotePath = d_remote['<STR_LIT:path>']<EOL>b_status = True<EOL><DEDENT>if '<STR_LIT:key>' in d_remote.keys():<EOL><INDENT>str_remotePath = d_remote['<STR_LIT:key>']<EOL>b_status = True<EOL><DEDENT>return {<EOL>'<STR_LIT:status>': b_status,<EOL>'<STR_LIT:path>': str_remotePath<EOL>}<EOL> | Resolve the remote "path" location by returning either the
'path' or 'key' parameter in the 'remote' JSON record.
:param d_remote:
:return: | f15684:c0:m4 |
def remoteLocation_resolve(self, d_remote): | b_status = False<EOL>str_remotePath = "<STR_LIT>"<EOL>if '<STR_LIT:path>' in d_remote.keys():<EOL><INDENT>str_remotePath = d_remote['<STR_LIT:path>']<EOL>b_status = True<EOL><DEDENT>if '<STR_LIT:key>' in d_remote.keys():<EOL><INDENT>d_ret = self.storage_resolveBasedOnKey(key = d_remote['<STR_LIT:key>'])<EOL>if d_ret['<STR_LIT:status>']:<EOL><INDENT>b_status = True<EOL>str_remotePath = d_ret['<STR_LIT:path>']<EOL><DEDENT><DEDENT>return {<EOL>'<STR_LIT:status>': b_status,<EOL>'<STR_LIT:path>': str_remotePath<EOL>}<EOL> | Resolve the remote path location
:param d_remote: the "remote" specification
:return: a string representation of the remote path | f15684:c0:m5 |
def man(self, **kwargs): | str_man = '<STR_LIT>'<EOL>str_amount = '<STR_LIT>'<EOL>for k, v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT>': str_man = v<EOL>if k == '<STR_LIT>': str_amount = v<EOL><DEDENT>if str_man == '<STR_LIT>':<EOL><INDENT>str_commands = """<STR_LIT>""" + Colors.GREEN + """<STR_LIT>""" + Colors.WHITE + """<STR_LIT>""" + Colors.GREEN + """<STR_LIT>""" + Colors.WHITE + """<STR_LIT>""" + Colors.GREEN + """<STR_LIT>""" % (self.str_ip, self.str_port) + Colors.CYAN + """<STR_LIT>""" + "<STR_LIT:\n>" +self.man_pushPath( description = "<STR_LIT>") + "<STR_LIT:\n>" +self.man_pullPath( description = "<STR_LIT>") + "<STR_LIT:\n>" +Colors.YELLOW +"""<STR_LIT>""" + Colors.LIGHT_CYAN +"""<STR_LIT>"""<EOL>return str_commands<EOL><DEDENT>if str_man == '<STR_LIT>': return self.man_pushPath( description = str_amount)<EOL>if str_man == '<STR_LIT>': return self.man_pullPath( description = str_amount)<EOL> | Print some man for each understood command | f15684:c0:m6 |
def pull_core(self, **kwargs): | str_ip = self.str_ip<EOL>str_port = self.str_port<EOL>verbose = <NUM_LIT:0><EOL>d_msg = {}<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT>': str_ip = v<EOL>if k == '<STR_LIT:port>': str_port = v<EOL>if k == '<STR_LIT>': d_msg = v<EOL>if k == '<STR_LIT>': verbose = v<EOL><DEDENT>response = io.BytesIO()<EOL>str_query = '<STR_LIT>'<EOL>if len(d_msg):<EOL><INDENT>d_meta = d_msg['<STR_LIT>']<EOL>str_query = '<STR_LIT>' % urllib.parse.urlencode(d_msg)<EOL><DEDENT>str_URL = "<STR_LIT>" % (self.str_protocol, str_ip, str_port, self.str_URL, str_query)<EOL>self.dp.qprint(str_URL,<EOL>comms = '<STR_LIT>')<EOL>c = pycurl.Curl()<EOL>c.setopt(c.URL, str_URL)<EOL>if self.b_unverifiedCerts:<EOL><INDENT>self.dp.qprint("<STR_LIT>")<EOL>c.setopt(pycurl.SSL_VERIFYPEER, <NUM_LIT:0>) <EOL>c.setopt(pycurl.SSL_VERIFYHOST, <NUM_LIT:0>)<EOL><DEDENT>if verbose: c.setopt(c.VERBOSE, <NUM_LIT:1>)<EOL>c.setopt(c.FOLLOWLOCATION, <NUM_LIT:1>)<EOL>c.setopt(c.WRITEFUNCTION, response.write)<EOL>if len(self.str_auth):<EOL><INDENT>self.dp.qprint("<STR_LIT>" % <EOL>self.str_auth)<EOL>c.setopt(c.USERPWD, self.str_auth)<EOL><DEDENT>elif len(self.str_authToken):<EOL><INDENT>self.dp.qprint("<STR_LIT>" % <EOL>self.str_authToken)<EOL>header = '<STR_LIT>' % self.str_authToken<EOL>c.setopt(pycurl.HTTPHEADER, [header])<EOL><DEDENT>self.dp.qprint("<STR_LIT>", level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>c.perform()<EOL>c.close()<EOL>try:<EOL><INDENT>str_response = response.getvalue().decode()<EOL><DEDENT>except:<EOL><INDENT>str_response = response.getvalue()<EOL><DEDENT>self.dp.qprint('<STR_LIT>' % "<STR_LIT>".format(len(str_response)),<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT>')<EOL>return str_response<EOL> | Just the core of the pycurl logic. | f15684:c0:m9 |
def pullPath_core(self, **kwargs): | d_msg = self.d_msg<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT>': d_msg = v<EOL><DEDENT>str_response = self.pull_core(msg = d_msg)<EOL>if len(str_response) < <NUM_LIT>:<EOL><INDENT>b_response = False<EOL>b_status = False<EOL>try:<EOL><INDENT>if self.b_httpResponseBodyParse:<EOL><INDENT>d_response = json.loads(self.httpResponse_bodyParse(response = str_response))<EOL><DEDENT>else:<EOL><INDENT>d_response = str_response<EOL><DEDENT>b_response = True<EOL>b_status = d_response['<STR_LIT:status>']<EOL>str_error = d_response<EOL><DEDENT>except:<EOL><INDENT>str_error = str_response<EOL><DEDENT>if not b_status or '<STR_LIT>' in str_response:<EOL><INDENT>self.dp.qprint('<STR_LIT>',<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:error>')<EOL>return {'<STR_LIT:status>': False,<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': str_error,<EOL>'<STR_LIT>': '<STR_LIT:%s>' % datetime.datetime.now(),<EOL>'<STR_LIT:size>': "<STR_LIT>".format(len(str_response))}<EOL><DEDENT>else:<EOL><INDENT>return {'<STR_LIT:status>': d_response['<STR_LIT:status>'],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': d_response,<EOL>'<STR_LIT>': '<STR_LIT:%s>' % datetime.datetime.now(),<EOL>'<STR_LIT:size>': "<STR_LIT>".format(len(str_response))}<EOL><DEDENT><DEDENT>self.dp.qprint("<STR_LIT>" + Colors.YELLOW + "<STR_LIT>".format(len(str_response)) +<EOL>Colors.PURPLE + "<STR_LIT>" ,<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>return {'<STR_LIT:status>': True,<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': str_response,<EOL>'<STR_LIT>': '<STR_LIT:%s>' % datetime.datetime.now(),<EOL>'<STR_LIT:size>': "<STR_LIT>".format(len(str_response))}<EOL> | Just the core of the pycurl logic. | f15684:c0:m10 |
def pullPath_compress(self, d_msg, **kwargs): | <EOL>d_meta = d_msg['<STR_LIT>']<EOL>if '<STR_LIT>' in d_meta:<EOL><INDENT>d_local = d_meta['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT:to>' in d_meta:<EOL><INDENT>d_local = d_meta['<STR_LIT:to>']<EOL><DEDENT>str_localPath = d_local['<STR_LIT:path>']<EOL>d_transport = d_meta['<STR_LIT>']<EOL>d_compress = d_transport['<STR_LIT>']<EOL>d_ret = {<EOL>'<STR_LIT>': {},<EOL>'<STR_LIT>': {}<EOL>}<EOL>str_uuid = uuid.uuid4()<EOL>str_unpackDir = '<STR_LIT>' % str_uuid<EOL>if not os.path.isdir(str_unpackDir):<EOL><INDENT>os.makedirs(str_unpackDir)<EOL><DEDENT>else:<EOL><INDENT>shutil.rmtree(str_unpackDir)<EOL>os.makedirs(str_unpackDir)<EOL><DEDENT>if not os.path.isdir(str_localPath):<EOL><INDENT>os.makedirs(str_localPath)<EOL><DEDENT>if '<STR_LIT>' in d_compress:<EOL><INDENT>b_cleanZip = d_compress['<STR_LIT>']<EOL><DEDENT>d_pull = self.pullPath_core()<EOL>d_ret['<STR_LIT>'] = d_pull<EOL>str_response = d_pull['<STR_LIT>']<EOL>d_pull['<STR_LIT>'] = '<STR_LIT>'<EOL>if not d_pull['<STR_LIT:status>']:<EOL><INDENT>if '<STR_LIT>' in d_pull:<EOL><INDENT>return {'<STR_LIT>': json.dumps(d_pull['<STR_LIT>'])}<EOL><DEDENT>else:<EOL><INDENT>raise Exception(d_pull['<STR_LIT>'])<EOL><DEDENT><DEDENT>str_fileSuffix = "<STR_LIT>"<EOL>if d_compress['<STR_LIT>'] == "<STR_LIT>": str_fileSuffix = "<STR_LIT>"<EOL>str_localFile = '<STR_LIT>' % (str_unpackDir, str_uuid) + str_fileSuffix<EOL>self.dp.qprint("<STR_LIT>" % str_localFile,<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>with open(str_localFile, '<STR_LIT:wb>') as fh:<EOL><INDENT>try: <EOL><INDENT>fh.write(str_response)<EOL>fh.close()<EOL>b_status = True<EOL>str_msg = '<STR_LIT>'<EOL><DEDENT>except:<EOL><INDENT>b_status = False<EOL>str_msg = '<STR_LIT>'<EOL><DEDENT><DEDENT>d_ret['<STR_LIT>']['<STR_LIT>'] = {}<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>'] = b_status<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = str_localFile<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT:%s>' % datetime.datetime.now()<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>".format(len(str_response))<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = str_msg<EOL>d_ret['<STR_LIT:status>'] = b_status<EOL>d_ret['<STR_LIT>'] = str_msg<EOL>if d_compress['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>self.dp.qprint("<STR_LIT>" % (str_localFile, str_unpackDir),<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>d_fio = zip_process(<EOL>action = "<STR_LIT>",<EOL>payloadFile = str_localFile,<EOL>path = str_unpackDir<EOL>)<EOL>d_ret['<STR_LIT>']['<STR_LIT>'] = d_fio<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT:%s>' % datetime.datetime.now()<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT:%s>' % "<STR_LIT>".format(os.stat(d_fio['<STR_LIT>']).st_size)<EOL>d_ret['<STR_LIT:status>'] = d_fio['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_fio['<STR_LIT>']<EOL>if d_meta['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>self.dp.qprint('<STR_LIT>' % str_localFile)<EOL>os.remove(str_localFile)<EOL><DEDENT><DEDENT>d_ret['<STR_LIT>']['<STR_LIT>'] = {}<EOL>self.dp.qprint('<STR_LIT>' % (str_unpackDir, str_localPath))<EOL>for str_file in glob.glob(str_unpackDir + '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>shutil.move(str_file, str_localPath)<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>'] = True<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT>'<EOL>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL><DEDENT>except:<EOL><INDENT>self.dp.qprint('<STR_LIT>', <EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:error>')<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>'] = False<EOL>d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT>'<EOL>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>break<EOL><DEDENT><DEDENT>if d_meta['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']: <EOL><INDENT>self.dp.qprint('<STR_LIT>' % str_unpackDir)<EOL>shutil.rmtree(str_unpackDir)<EOL><DEDENT>self.dp.qprint("<STR_LIT>" % self.pp.pformat(d_ret).strip(), level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>return d_ret<EOL> | This pulls a compressed path from a remote host/location.
Zip archives are universally unpacked to
/tmp/unpack-<uuid.uuid4()>
and then the file contents are moved to the actual destination
directory. In shell, this would be:
mkdir /tmp/unpack-<uuid.uuid4()>
cp file.zip /tmp/unpack-<uuid.uuid4()>
unzip /tmp/unpack-<uuid.uuid4()>/file.zip
mv /tmp/unpack-<uuid.uuid4()>/* <destination>
rm -fr /tmp/unpack-<uuid.uuid4()> | f15684:c0:m11 |
def pullPath_copy(self, d_msg, **kwargs): | <EOL>d_meta = d_msg['<STR_LIT>']<EOL>d_local = d_meta['<STR_LIT>']<EOL>str_localPath = d_local['<STR_LIT:path>']<EOL>d_remote = d_meta['<STR_LIT>']<EOL>d_transport = d_meta['<STR_LIT>']<EOL>d_copy = d_transport['<STR_LIT>']<EOL>d_curl = {}<EOL>d_curl['<STR_LIT>'] = self.pullPath_core()<EOL>d_curl['<STR_LIT>'] = {}<EOL>d_curl['<STR_LIT>']['<STR_LIT:status>'] = d_curl['<STR_LIT>']['<STR_LIT:status>']<EOL>if not d_curl['<STR_LIT>']['<STR_LIT:status>']:<EOL><INDENT>d_curl['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>d_curl['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>return d_curl<EOL> | Handle the "copy" pull operation | f15684:c0:m12 |
def path_remoteLocationCheck(self, d_msg, **kwargs): | <EOL>d_pull = self.pullPath_core()<EOL>return d_pull<EOL> | This method checks if the "remote" path is valid. | f15684:c0:m13 |
def path_localLocationCheck(self, d_msg, **kwargs): | b_pull = False<EOL>d_meta = d_msg['<STR_LIT>']<EOL>if '<STR_LIT>' in d_meta:<EOL><INDENT>if d_meta['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>b_pull = True<EOL><DEDENT><DEDENT>if '<STR_LIT>' in d_meta:<EOL><INDENT>d_local = d_meta['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT:to>' in d_meta:<EOL><INDENT>d_local = d_meta['<STR_LIT:to>']<EOL><DEDENT>str_localPathFull = d_local['<STR_LIT:path>']<EOL>str_localPath, str_unpack = os.path.split(str_localPathFull)<EOL>str_msg = '<STR_LIT>'<EOL>str_checkedDir = str_localPathFull<EOL>b_isFile = os.path.isfile(str_localPathFull)<EOL>b_isDir = os.path.isdir(str_localPathFull)<EOL>b_exists = os.path.exists(str_localPathFull)<EOL>if '<STR_LIT>' in d_msg['<STR_LIT:action>'] or b_pull:<EOL><INDENT>str_checkedDir = str_localPath<EOL>b_isFile = os.path.isfile(str_localPath)<EOL>b_isDir = os.path.isdir(str_localPath)<EOL>b_exists = os.path.exists(str_localPath)<EOL>if '<STR_LIT>' in d_local.keys():<EOL><INDENT>if d_local['<STR_LIT>']:<EOL><INDENT>if os.path.isdir(str_localPathFull):<EOL><INDENT>self.dp.qprint('<STR_LIT>' % str_localPathFull)<EOL>shutil.rmtree(str_localPathFull)<EOL>str_msg = '<STR_LIT>'<EOL><DEDENT>self.dp.qprint('<STR_LIT>' % str_localPathFull)<EOL>os.makedirs(str_localPathFull)<EOL>b_exists = True<EOL>str_msg += '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>str_msg = '<STR_LIT>'<EOL>if '<STR_LIT>' in d_local.keys():<EOL><INDENT>if not d_local['<STR_LIT>']: <EOL><INDENT>if b_isDir: b_exists = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if b_isDir: b_exists = False<EOL><DEDENT><DEDENT><DEDENT>d_ret = {<EOL>'<STR_LIT:action>': d_msg['<STR_LIT:action>'],<EOL>'<STR_LIT>': str_checkedDir,<EOL>'<STR_LIT:status>': b_exists,<EOL>'<STR_LIT>': b_isFile,<EOL>'<STR_LIT>': b_isDir,<EOL>'<STR_LIT>': str_msg<EOL>}<EOL>return {'<STR_LIT>': d_ret,<EOL>'<STR_LIT:status>': d_ret['<STR_LIT:status>'],<EOL>'<STR_LIT>': '<STR_LIT:%s>' % datetime.datetime.now()}<EOL> | Check if a path exists on the local filesystem
:param self:
:param kwargs:
:return: | f15684:c0:m14 |
def pushPath_copy(self, d_msg, **kwargs): | <EOL>d_meta = d_msg['<STR_LIT>']<EOL>d_local = d_meta['<STR_LIT>']<EOL>str_localPath = d_local['<STR_LIT:path>']<EOL>d_remote = d_meta['<STR_LIT>']<EOL>d_transport = d_meta['<STR_LIT>']<EOL>d_copy = d_transport['<STR_LIT>']<EOL>d_curl = {<EOL>'<STR_LIT>': self.push_core(d_msg),<EOL>'<STR_LIT>': {}<EOL>}<EOL>d_curl['<STR_LIT>']['<STR_LIT:status>'] = d_curl['<STR_LIT>']['<STR_LIT:status>']<EOL>if not d_curl['<STR_LIT>']['<STR_LIT:status>']:<EOL><INDENT>d_curl['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>d_curl['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>return d_curl<EOL> | Handle the "copy" pull operation | f15684:c0:m18 |
def pathOp_do(self, d_msg, **kwargs): | d_meta = d_msg['<STR_LIT>']<EOL>b_OK = True<EOL>d_ret = {}<EOL>str_action = "<STR_LIT>"<EOL>for k,v, in kwargs.items():<EOL><INDENT>if k == '<STR_LIT:action>': str_action = v<EOL><DEDENT>if not '<STR_LIT>' in d_meta:<EOL><INDENT>d_transport = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT>": True<EOL>}<EOL>}<EOL>d_meta['<STR_LIT>'] = d_transport <EOL><DEDENT>else:<EOL><INDENT>d_transport = d_meta['<STR_LIT>']<EOL><DEDENT>self.dp.qprint('<STR_LIT>', level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>d_ret['<STR_LIT>'] = self.path_localLocationCheck(d_msg)<EOL>if not d_ret['<STR_LIT>']['<STR_LIT:status>']:<EOL><INDENT>self.dp.qprint('<STR_LIT>',<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:error>')<EOL>d_ret['<STR_LIT>']['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>d_ret['<STR_LIT>']['<STR_LIT:status>'] = False<EOL>b_OK = False<EOL>self.dp.qprint("<STR_LIT>" % self.pp.pformat(d_ret).strip(), level = <NUM_LIT:1>, comms ='<STR_LIT:error>')<EOL><DEDENT>else:<EOL><INDENT>d_ret['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']<EOL>if b_OK:<EOL><INDENT>d_transport['<STR_LIT>'] = True<EOL>self.dp.qprint('<STR_LIT>', level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>remoteCheck = self.path_remoteLocationCheck(d_msg)<EOL>d_ret['<STR_LIT>'] = remoteCheck<EOL>self.dp.qprint("<STR_LIT>" % self.pp.pformat(d_ret).strip(), level = <NUM_LIT:1>, comms ='<STR_LIT>')<EOL>if not d_ret['<STR_LIT>']['<STR_LIT:status>']:<EOL><INDENT>self.dp.qprint('<STR_LIT>',<EOL>level = <NUM_LIT:1>, comms ='<STR_LIT:error>')<EOL>d_ret['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL>b_OK = False<EOL><DEDENT>else:<EOL><INDENT>d_ret['<STR_LIT>']['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>d_transport['<STR_LIT>'] = False<EOL>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']<EOL><DEDENT>b_jobExec = False<EOL>if b_OK:<EOL><INDENT>if '<STR_LIT>' in d_transport and d_ret['<STR_LIT:status>']:<EOL><INDENT>self.dp.qprint('<STR_LIT>' % str_action, level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>d_ret['<STR_LIT>'] = eval("<STR_LIT>" % str_action)<EOL>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']<EOL>b_jobExec = True<EOL><DEDENT>if '<STR_LIT>' in d_transport:<EOL><INDENT>self.dp.qprint('<STR_LIT>' % str_action, level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>d_ret['<STR_LIT>'] = eval("<STR_LIT>" % str_action)<EOL>d_ret['<STR_LIT:status>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT:status>']<EOL>d_ret['<STR_LIT>'] = d_ret['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>b_jobExec = True<EOL><DEDENT><DEDENT>if not b_jobExec:<EOL><INDENT>d_ret['<STR_LIT:status>'] = False<EOL>d_ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if self.b_oneShot:<EOL><INDENT>d_ret['<STR_LIT>'] = self.server_ctlQuit(d_msg)<EOL><DEDENT>return {'<STR_LIT>': d_ret}<EOL> | Entry point for path-based push/pull calls.
Essentially, this method is the central dispatching nexus to various
specialized push operations. | f15684:c0:m19 |
def server_ctlQuit(self, d_msg): | d_shutdown = {}<EOL>d_meta = d_msg['<STR_LIT>']<EOL>d_meta['<STR_LIT>'] = {<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>self.dp.qprint('<STR_LIT>', level = <NUM_LIT:1>, comms ='<STR_LIT:status>')<EOL>try:<EOL><INDENT>d_shutdown = self.push_core(d_msg)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>return d_shutdown<EOL> | :return: d_shutdown shut down JSON message from remote service. | f15684:c0:m20 |
def pushPath(self, d_msg, **kwargs): | return self.pathOp_do(d_msg, action = '<STR_LIT>')<EOL> | Push data to a remote server using pycurl.
Essentially, this method is the central dispatching nexus to various
specialized push operations. | f15684:c0:m21 |
def pullPath(self, d_msg, **kwargs): | return self.pathOp_do(d_msg, action = '<STR_LIT>')<EOL> | Pulls data from a remote server using pycurl.
This method assumes that a prior call has "setup" a remote fileio
listener and has the ip:port of that instance.
Essentially, this method is the central dispatching nexus to various
specialized pull operations.
:param d_msg:
:param kwargs:
:return: | f15684:c0:m22 |
def httpResponse_bodyParse(self, **kwargs): | str_response = '<STR_LIT>'<EOL>for k,v in kwargs.items():<EOL><INDENT>if k == '<STR_LIT>': str_response = v<EOL><DEDENT>try:<EOL><INDENT>str_body = str_response.split('<STR_LIT>')[<NUM_LIT:1>]<EOL>d_body = yaml.load(str_body)<EOL>str_body = json.dumps(d_body)<EOL><DEDENT>except:<EOL><INDENT>str_body = str_response<EOL><DEDENT>return str_body<EOL> | Returns the *body* from a http response.
:param kwargs: response = <string>
:return: the <body> from the http <string> | f15684:c0:m24 |
def __call__(self, *args, **kwargs): | str_action = '<STR_LIT>'<EOL>http = '<STR_LIT>'<EOL>for key,val in kwargs.items():<EOL><INDENT>if key == '<STR_LIT>':<EOL><INDENT>self.str_msg = val<EOL>self.d_msg = json.loads(self.str_msg)<EOL><DEDENT>if key == '<STR_LIT:http>': self.httpStr_parse(http = val)<EOL>if key == '<STR_LIT>': self.str_verb = val<EOL>if key == '<STR_LIT>': self.b_unverifiedCerts = val<EOL><DEDENT>if len(self.str_msg):<EOL><INDENT>if '<STR_LIT:action>' in self.d_msg: str_action = self.d_msg['<STR_LIT:action>']<EOL>if '<STR_LIT:path>' in str_action.lower():<EOL><INDENT>d_ret = self.pathOp_do(self.d_msg, action = str_action)<EOL><DEDENT>else:<EOL><INDENT>if self.str_verb == '<STR_LIT:GET>':<EOL><INDENT>d_ret = self.pull_core(msg = self.d_msg)<EOL><DEDENT>if self.str_verb == '<STR_LIT:POST>':<EOL><INDENT>d_ret = self.push_core(self.d_msg)<EOL><DEDENT><DEDENT>str_stdout = json.dumps(d_ret)<EOL><DEDENT>else:<EOL><INDENT>d_ret = self.pull_core()<EOL>str_stdout = '<STR_LIT:%s>' % d_ret<EOL><DEDENT>if not self.b_quiet: print(Colors.CYAN)<EOL>return str_stdout<EOL> | Main entry point for "calling".
:param self:
:param kwargs:
:return: | f15684:c0:m25 |
def prepare_value(self, value): | if value is None and self.required:<EOL><INDENT>choices =list(self.choices)<EOL>if len(choices) == <NUM_LIT:1>:<EOL><INDENT>value = choices[<NUM_LIT:0>][<NUM_LIT:0>]<EOL><DEDENT><DEDENT>return super(TemplateChoiceField, self).prepare_value(value)<EOL> | To avoid evaluating the lazysorted callable more than necessary to
establish a potential initial value for the field, we do it here.
If there's
- only one template choice, and
- the field is required, and
- there's no prior initial set (either by being bound or by being set
higher up the stack
then forcibly select the only "good" value as the default. | f15694:c2:m1 |
def from_cached(instance): | loaders = instance.loaders<EOL>for result in get_results_from_registry(loaders):<EOL><INDENT>yield result<EOL><DEDENT> | Just go and look at the registry again using the child loaders... | f15696:m2 |
def needs_quotes( s ): | <EOL>if s in dot_keywords:<EOL><INDENT>return False<EOL><DEDENT>chars = [ord(c) for c in s if ord(c)><NUM_LIT> or ord(c)==<NUM_LIT:0>]<EOL>if chars and not id_re_dbl_quoted.match(s) and not id_re_html.match(s):<EOL><INDENT>return True<EOL><DEDENT>for test_re in [id_re_alpha_nums, id_re_num,<EOL>id_re_dbl_quoted, id_re_html,<EOL>id_re_alpha_nums_with_ports]:<EOL><INDENT>if test_re.match(s):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>m = id_re_with_port.match(s)<EOL>if m:<EOL><INDENT>return needs_quotes(m.group(<NUM_LIT:1>)) or needs_quotes(m.group(<NUM_LIT:2>))<EOL><DEDENT>return True<EOL> | Checks whether a string is a dot language ID.
It will check whether the string is solely composed
by the characters allowed in an ID or not.
If the string is one of the reserved keywords it will
need quotes too but the user will need to add them
manually. | f15701:m4 |
def quote_if_necessary(s): | if isinstance(s, bool):<EOL><INDENT>if s is True:<EOL><INDENT>return '<STR_LIT:True>'<EOL><DEDENT>return '<STR_LIT:False>'<EOL><DEDENT>if not isinstance( s, str_type):<EOL><INDENT>return s<EOL><DEDENT>if not s:<EOL><INDENT>return s<EOL><DEDENT>if needs_quotes(s):<EOL><INDENT>replace = {'<STR_LIT:">' : r'<STR_LIT>',<EOL>"<STR_LIT:\n>" : r'<STR_LIT:\n>',<EOL>"<STR_LIT:\r>" : r'<STR_LIT:\r>'}<EOL>for (a,b) in replace.items():<EOL><INDENT>s = s.replace(a, b)<EOL><DEDENT>return '<STR_LIT:">' + s + '<STR_LIT:">'<EOL><DEDENT>return s<EOL> | Enclode attribute value in quotes, if needed. | f15701:m5 |
def graph_from_dot_data(s): | return dot_parser.parse_dot_data(s)<EOL> | Load graphs from DOT description in string `s`.
@param s: string in [DOT language](
https://en.wikipedia.org/wiki/DOT_(graph_description_language))
@return: Graphs that result from parsing.
@rtype: `list` of `pydot.Dot` | f15701:m6 |
def graph_from_dot_file(path, encoding=None): | with io.open(path, '<STR_LIT>', encoding=encoding) as f:<EOL><INDENT>s = f.read()<EOL><DEDENT>if not PY3:<EOL><INDENT>s = unicode(s)<EOL><DEDENT>graphs = graph_from_dot_data(s)<EOL>return graphs<EOL> | Load graphs from DOT file at `path`.
@param path: to DOT file
@param encoding: as passed to `io.open`.
For example, `'utf-8'`.
@return: Graphs that result from parsing.
@rtype: `list` of `pydot.Dot` | f15701:m7 |
def graph_from_edges(edge_list, node_prefix='<STR_LIT>', directed=False): | if directed:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>for edge in edge_list:<EOL><INDENT>if isinstance(edge[<NUM_LIT:0>], str):<EOL><INDENT>src = node_prefix + edge[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>src = node_prefix + str(edge[<NUM_LIT:0>])<EOL><DEDENT>if isinstance(edge[<NUM_LIT:1>], str):<EOL><INDENT>dst = node_prefix + edge[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>dst = node_prefix + str(edge[<NUM_LIT:1>])<EOL><DEDENT>e = Edge( src, dst )<EOL>graph.add_edge(e)<EOL><DEDENT>return graph<EOL> | Creates a basic graph out of an edge list.
The edge list has to be a list of tuples representing
the nodes connected by the edge.
The values can be anything: bool, int, float, str.
If the graph is undirected by default, it is only
calculated from one of the symmetric halves of the matrix. | f15701:m8 |
def graph_from_adjacency_matrix(matrix, node_prefix= u'<STR_LIT>', directed=False): | node_orig = <NUM_LIT:1><EOL>if directed:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>for row in matrix:<EOL><INDENT>if not directed:<EOL><INDENT>skip = matrix.index(row)<EOL>r = row[skip:]<EOL><DEDENT>else:<EOL><INDENT>skip = <NUM_LIT:0><EOL>r = row<EOL><DEDENT>node_dest = skip+<NUM_LIT:1><EOL>for e in r:<EOL><INDENT>if e:<EOL><INDENT>graph.add_edge(<EOL>Edge( node_prefix + node_orig,<EOL>node_prefix + node_dest) )<EOL><DEDENT>node_dest += <NUM_LIT:1><EOL><DEDENT>node_orig += <NUM_LIT:1><EOL><DEDENT>return graph<EOL> | Creates a basic graph out of an adjacency matrix.
The matrix has to be a list of rows of values
representing an adjacency matrix.
The values can be anything: bool, int, float, as long
as they can evaluate to True or False. | f15701:m9 |
def graph_from_incidence_matrix(matrix, node_prefix='<STR_LIT>', directed=False): | node_orig = <NUM_LIT:1><EOL>if directed:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>graph = Dot(graph_type='<STR_LIT>')<EOL><DEDENT>for row in matrix:<EOL><INDENT>nodes = []<EOL>c = <NUM_LIT:1><EOL>for node in row:<EOL><INDENT>if node:<EOL><INDENT>nodes.append(c*node)<EOL><DEDENT>c += <NUM_LIT:1><EOL>nodes.sort()<EOL><DEDENT>if len(nodes) == <NUM_LIT:2>:<EOL><INDENT>graph.add_edge(<EOL>Edge( node_prefix + abs(nodes[<NUM_LIT:0>]),<EOL>node_prefix + nodes[<NUM_LIT:1>] ))<EOL><DEDENT><DEDENT>if not directed:<EOL><INDENT>graph.set_simplify(True)<EOL><DEDENT>return graph<EOL> | Creates a basic graph out of an incidence matrix.
The matrix has to be a list of rows of values
representing an incidence matrix.
The values can be anything: bool, int, float, as long
as they can evaluate to True or False. | f15701:m10 |
def __get_attribute__(self, attr): | attr_val = self.obj_dict['<STR_LIT>'].get(attr, None)<EOL>if attr_val is None:<EOL><INDENT>default_node_name = self.obj_dict['<STR_LIT:type>']<EOL>if default_node_name in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>default_node_name = '<STR_LIT>'<EOL><DEDENT>g = self.get_parent_graph()<EOL>if g is not None:<EOL><INDENT>defaults = g.get_node( default_node_name )<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>if not isinstance(defaults, (list, tuple)):<EOL><INDENT>defaults = [defaults]<EOL><DEDENT>for default in defaults:<EOL><INDENT>attr_val = default.obj_dict['<STR_LIT>'].get(attr, None)<EOL>if attr_val:<EOL><INDENT>return attr_val<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return attr_val<EOL><DEDENT>return None<EOL> | Look for default attributes for this node | f15701:c1:m2 |
def set(self, name, value): | self.obj_dict['<STR_LIT>'][name] = value<EOL> | Set an attribute value by name.
Given an attribute 'name' it will set its value to 'value'.
There's always the possibility of using the methods:
set_'name'(value)
which are defined for all the existing attributes. | f15701:c1:m5 |
def get(self, name): | return self.obj_dict['<STR_LIT>'].get(name, None)<EOL> | Get an attribute value by name.
Given an attribute 'name' it will get its value.
There's always the possibility of using the methods:
get_'name'()
which are defined for all the existing attributes. | f15701:c1:m6 |
def set_name(self, node_name): | self.obj_dict['<STR_LIT:name>'] = node_name<EOL> | Set the node's name. | f15701:c4:m2 |
def get_name(self): | return self.obj_dict['<STR_LIT:name>']<EOL> | Get the node's name. | f15701:c4:m3 |
def get_port(self): | return self.obj_dict['<STR_LIT:port>']<EOL> | Get the node's port. | f15701:c4:m4 |
def to_string(self): | <EOL>node = quote_if_necessary(self.obj_dict['<STR_LIT:name>'])<EOL>node_attr = list()<EOL>for attr in sorted(self.obj_dict['<STR_LIT>']):<EOL><INDENT>value = self.obj_dict['<STR_LIT>'][attr]<EOL>if value == '<STR_LIT>':<EOL><INDENT>value = '<STR_LIT>'<EOL><DEDENT>if value is not None:<EOL><INDENT>node_attr.append(<EOL>'<STR_LIT>' % (attr, quote_if_necessary(value) ) )<EOL><DEDENT>else:<EOL><INDENT>node_attr.append( attr )<EOL><DEDENT><DEDENT>if node in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>') and len(node_attr) == <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>node_attr = '<STR_LIT:U+002CU+0020>'.join(node_attr)<EOL>if node_attr:<EOL><INDENT>node += '<STR_LIT>' + node_attr + '<STR_LIT:]>'<EOL><DEDENT>return node + '<STR_LIT:;>'<EOL> | Return string representation of node in DOT language. | f15701:c4:m6 |
def get_source(self): | return self.obj_dict['<STR_LIT>'][<NUM_LIT:0>]<EOL> | Get the edges source node name. | f15701:c5:m2 |
def get_destination(self): | return self.obj_dict['<STR_LIT>'][<NUM_LIT:1>]<EOL> | Get the edge's destination node name. | f15701:c5:m3 |
def __eq__(self, edge): | if not isinstance(edge, Edge):<EOL><INDENT>raise Error('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if self.get_parent_graph().get_top_graph_type() == '<STR_LIT>':<EOL><INDENT>if ( ( self.get_source() == edge.get_source() and<EOL>self.get_destination() == edge.get_destination() ) or<EOL>( edge.get_source() == self.get_destination() and<EOL>edge.get_destination() == self.get_source() ) ):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (self.get_source()==edge.get_source() and<EOL>self.get_destination()==edge.get_destination()):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL> | Compare two edges.
If the parent graph is directed, arcs linking
node A to B are considered equal and A->B != B->A
If the parent graph is undirected, any edge
connecting two nodes is equal to any other
edge connecting the same nodes, A->B == B->A | f15701:c5:m5 |
def to_string(self): | src = self.parse_node_ref( self.get_source() )<EOL>dst = self.parse_node_ref( self.get_destination() )<EOL>if isinstance(src, frozendict):<EOL><INDENT>edge = [ Subgraph(obj_dict=src).to_string() ]<EOL><DEDENT>elif isinstance(src, int):<EOL><INDENT>edge = [ str(src) ]<EOL><DEDENT>else:<EOL><INDENT>edge = [ src ]<EOL><DEDENT>if (self.get_parent_graph() and<EOL>self.get_parent_graph().get_top_graph_type() and<EOL>self.get_parent_graph().get_top_graph_type() == '<STR_LIT>' ):<EOL><INDENT>edge.append( '<STR_LIT>' )<EOL><DEDENT>else:<EOL><INDENT>edge.append( '<STR_LIT>' )<EOL><DEDENT>if isinstance(dst, frozendict):<EOL><INDENT>edge.append( Subgraph(obj_dict=dst).to_string() )<EOL><DEDENT>elif isinstance(dst, int):<EOL><INDENT>edge.append( str(dst) )<EOL><DEDENT>else:<EOL><INDENT>edge.append( dst )<EOL><DEDENT>edge_attr = list()<EOL>for attr in sorted(self.obj_dict['<STR_LIT>']):<EOL><INDENT>value = self.obj_dict['<STR_LIT>'][attr]<EOL>if value == '<STR_LIT>':<EOL><INDENT>value = '<STR_LIT>'<EOL><DEDENT>if value is not None:<EOL><INDENT>edge_attr.append(<EOL>'<STR_LIT>' % (attr, quote_if_necessary(value) ) )<EOL><DEDENT>else:<EOL><INDENT>edge_attr.append( attr )<EOL><DEDENT><DEDENT>edge_attr = '<STR_LIT:U+002CU+0020>'.join(edge_attr)<EOL>if edge_attr:<EOL><INDENT>edge.append( '<STR_LIT>' + edge_attr + '<STR_LIT:]>' )<EOL><DEDENT>return '<STR_LIT:U+0020>'.join(edge) + '<STR_LIT:;>'<EOL> | Return string representation of edge in DOT language. | f15701:c5:m7 |
def set_simplify(self, simplify): | self.obj_dict['<STR_LIT>'] = simplify<EOL> | Set whether to simplify or not.
If True it will avoid displaying equal edges, i.e.
only one edge between two nodes. removing the
duplicated ones. | f15701:c6:m10 |
def get_simplify(self): | return self.obj_dict['<STR_LIT>']<EOL> | Get whether to simplify or not.
Refer to set_simplify for more information. | f15701:c6:m11 |
def set_type(self, graph_type): | self.obj_dict['<STR_LIT:type>'] = graph_type<EOL> | Set the graph's type, 'graph' or 'digraph'. | f15701:c6:m12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.