code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
namespaces = ct.Namespaces(**namespaces)
custom = kwargs.get('custom')
if custom is not None:
custom = ct.CustomSelectors(**custom)
if isinstance(pattern, SoupSieve):
if flags:
raise ValueError("Cannot process 'flags' argument on a compiled selector list")
elif ... | def compile(pattern, namespaces=None, flags=0, **kwargs): # noqa: A001
if namespaces is not None | Compile CSS pattern. | 5.623659 | 4.642636 | 1.211307 |
return compile(select, namespaces, flags, **kwargs).closest(tag) | def closest(select, tag, namespaces=None, flags=0, **kwargs) | Match closest ancestor. | 10.360913 | 8.313814 | 1.246229 |
return compile(select, namespaces, flags, **kwargs).match(tag) | def match(select, tag, namespaces=None, flags=0, **kwargs) | Match node. | 6.842981 | 6.514735 | 1.050385 |
def filter(select, iterable, namespaces=None, flags=0, **kwargs): # noqa: A001
return compile(select, namespaces, flags, **kwargs).filter(iterable) | Filter list of nodes. | null | null | null | |
return [comment for comment in cm.CommentsMatch(tag).get_comments(limit)] | def comments(tag, limit=0, flags=0, **kwargs) | Get comments only. | 22.378204 | 19.71785 | 1.134921 |
return compile(select, namespaces, flags, **kwargs).select_one(tag) | def select_one(select, tag, namespaces=None, flags=0, **kwargs) | Select a single tag. | 7.294319 | 6.323229 | 1.153575 |
return compile(select, namespaces, flags, **kwargs).select(tag, limit) | def select(select, tag, namespaces=None, limit=0, flags=0, **kwargs) | Select the specified tags. | 9.03167 | 8.439386 | 1.070181 |
for el in compile(select, namespaces, flags, **kwargs).iselect(tag, limit):
yield el | def iselect(select, tag, namespaces=None, limit=0, flags=0, **kwargs) | Iterate the specified tags. | 11.530352 | 9.668357 | 1.192586 |
request = cls._make_request('GET', cls._get_all_path(), connection, params=params)
return cls._create_object(request, connection=connection) | def all(cls, connection=None, **params) | Returns first page if no params passed in as a list. | 5.21197 | 4.726738 | 1.102657 |
try:
limit = kwargs['limit']
except KeyError:
limit = None
try:
page = kwargs['page']
except KeyError:
page = None
def _all_responses():
page = 1 # one based
params = kwargs.copy()
w... | def iterall(cls, connection=None, **kwargs) | Returns a autopaging generator that yields each object returned one by one. | 3.131404 | 3.017041 | 1.037906 |
if rid:
if resource[-1] != '/':
resource += '/'
resource += str(rid)
response = self._run_method('GET', resource, query=query)
return self._handle_response(resource, response) | def get(self, resource="", rid=None, **query) | Retrieves the resource with given id 'rid', or all resources of given type.
Keep in mind that the API returns a list for any query that doesn't specify an ID, even when applying
a limit=1 filter.
Also be aware that float values tend to come back as strings ("2.0000" instead of 2.0)
Keyw... | 3.328432 | 4.114304 | 0.80899 |
if resource[-1] != '/':
resource += '/'
resource += str(rid)
return self.put(resource, data=updates) | def update(self, resource, rid, updates) | Updates the resource with id 'rid' with the given updates dictionary. | 4.198846 | 3.857449 | 1.088503 |
if resource[-1] != '/':
resource += '/'
resource += str(rid)
response = self._run_method('DELETE', resource)
return self._handle_response(resource, response, suppress_empty=True) | def delete(self, resource, rid=None): # note that rid can't be 0 - problem?
if rid | Deletes the resource with given id 'rid', or all resources of given type if rid is not supplied. | 7.551818 | 5.969725 | 1.265019 |
response = self._run_method('PUT', url, data=data)
log.debug("OUTPUT: %s" % response.content)
return self._handle_response(url, response) | def put(self, url, data) | Make a PUT request to save data.
data should be a dictionary. | 4.583653 | 4.509381 | 1.016471 |
response = self._run_method('POST', url, data=data, headers=headers)
return self._handle_response(url, response) | def post(self, url, data, headers={}) | POST request for creating new objects.
data should be a dictionary. | 3.627533 | 3.3677 | 1.077154 |
self._last_response = res
result = {}
if res.status_code in (200, 201, 202):
try:
result = res.json()
except Exception as e: # json might be invalid, or store might be down
e.message += " (_handle_response failed to decode JSON: "... | def _handle_response(self, url, res, suppress_empty=True) | Returns parsed JSON or raises an exception appropriately. | 1.993449 | 1.923556 | 1.036335 |
encoded_json, encoded_hmac = signed_payload.split('.')
dc_json = base64.b64decode(encoded_json)
signature = base64.b64decode(encoded_hmac)
expected_sig = hmac.new(client_secret.encode(), base64.b64decode(encoded_json), hashlib.sha256).hexdigest()
authorised = hmac.compar... | def verify_payload(signed_payload, client_secret) | Given a signed payload (usually passed as parameter in a GET request to the app's load URL) and a client secret,
authenticates the payload and returns the user's data, or False on fail.
Uses constant-time str comparison to prevent vulnerability to timing attacks. | 2.601664 | 2.371256 | 1.097167 |
res = self.post(token_url, {'client_id': self.client_id,
'client_secret': client_secret,
'code': code,
'context': context,
'scope': scope,
... | def fetch_token(self, client_secret, code, context, scope, redirect_uri,
token_url='https://login.bigcommerce.com/oauth2/token') | Fetches a token from given token_url, using given parameters, and sets up session headers for
future requests.
redirect_uri should be the same as your callback URL.
code, context, and scope should be passed as parameters to your callback URL on app installation.
Raises HttpException on ... | 1.963868 | 1.940658 | 1.01196 |
result = Connection._handle_response(self, url, res, suppress_empty)
if 'X-Rate-Limit-Time-Reset-Ms' in res.headers:
self.rate_limit = dict(ms_until_reset=int(res.headers['X-Rate-Limit-Time-Reset-Ms']),
window_size_ms=int(res.headers['X-Rate-Limit-... | def _handle_response(self, url, res, suppress_empty=True) | Adds rate limiting information on to the response object | 2.477981 | 2.362396 | 1.048927 |
byte_str = text.encode('utf-8')
ob = lib.hoedown_buffer_new(OUNIT)
lib.hoedown_escape_html(ob, byte_str, len(byte_str), int(escape_slash))
try:
return to_string(ob)
finally:
lib.hoedown_buffer_free(ob) | def escape_html(text, escape_slash=False) | Binding for Hoedown's HTML escaping function.
The implementation is inspired by the OWASP XSS Prevention recommendations:
.. code-block:: none
& --> &
< --> <
> --> >
" --> "
' --> '
/ --> / when escape_slash is set to True
.. ver... | 4.946358 | 5.857735 | 0.844415 |
extensions = args_to_int(extension_map, extensions)
render_flags = args_to_int(html_flag_map, render_flags)
ib = lib.hoedown_buffer_new(IUNIT)
ob = lib.hoedown_buffer_new(OUNIT)
renderer = lib.hoedown_html_renderer_new(render_flags, 0)
document = lib.hoedown_document_new(renderer, extensio... | def html(text, extensions=0, render_flags=0) | Convert markdown text to HTML.
``extensions`` can be a list or tuple of extensions (e.g.
``('fenced-code', 'footnotes', 'strikethrough')``) or an integer
(e.g. ``EXT_FENCED_CODE | EXT_FOOTNOTES | EXT_STRIKETHROUGH``).
``render_flags`` can be a list or tuple of flags (e.g.
``('skip-html', 'hard-wra... | 3.212556 | 3.641034 | 0.88232 |
byte_str = text.encode('utf-8')
ob = lib.hoedown_buffer_new(OUNIT)
lib.hoedown_html_smartypants(ob, byte_str, len(byte_str))
try:
return to_string(ob)
finally:
lib.hoedown_buffer_free(ob); | def smartypants(text) | Transforms sequences of characters into HTML entities.
=================================== ===================== =========
Markdown HTML Result
=================================== ===================== =========
``'s`` (s, t, m, d, re, ll, ve) &rsq... | 6.058212 | 7.940225 | 0.762977 |
if self.check_url(raw_url):
url = self.rewrite_url(('mailto:' if is_email else '') + raw_url)
url = escape_html(url)
return '<a href="%s">%s</a>' % (url, escape_html(raw_url))
else:
return escape_html('<%s>' % raw_url) | def autolink(self, raw_url, is_email) | Filters links generated by the ``autolink`` extension. | 2.773404 | 2.819677 | 0.983589 |
if self.check_url(raw_url, is_image_src=True):
url = self.rewrite_url(raw_url, is_image_src=True)
maybe_alt = ' alt="%s"' % escape_html(alt) if alt else ''
maybe_title = ' title="%s"' % escape_html(title) if title else ''
url = escape_html(url)
... | def image(self, raw_url, title='', alt='') | Filters the ``src`` attribute of an image.
Note that filtering the source URL of an ``<img>`` tag is only a very
basic protection, and it's mostly useless in modern browsers (they block
JavaScript in there by default). An example of attack that filtering
does not thwart is phishing base... | 2.399463 | 2.346298 | 1.022659 |
if self.check_url(raw_url):
url = self.rewrite_url(raw_url)
maybe_title = ' title="%s"' % escape_html(title) if title else ''
url = escape_html(url)
return ('<a href="%s"%s>' % (url, maybe_title)) + content + '</a>'
else:
return escap... | def link(self, content, raw_url, title='') | Filters links. | 3.032062 | 3.006151 | 1.008619 |
return bool(self._allowed_url_re.match(url)) | def check_url(self, url, is_image_src=False) | This method is used to check a URL.
Returns :obj:`True` if the URL is "safe", :obj:`False` otherwise.
The default implementation only allows HTTP and HTTPS links. That means
no ``mailto:``, no ``xmpp:``, no ``ftp:``, etc.
This method exists specifically to allow easy customization of ... | 11.882514 | 14.315186 | 0.830064 |
rewrite = self.img_src_rewrite if is_image_src else self.link_rewrite
if rewrite:
return rewrite.format(url=urlquote(url))
return url | def rewrite_url(self, url, is_image_src=False) | This method is called to rewrite URLs.
It uses either ``self.link_rewrite`` or ``self.img_src_rewrite``
depending on the value of ``is_image_src``. The URL is returned
unchanged if the corresponding attribute is :obj:`None`. | 4.768953 | 4.055655 | 1.175877 |
if isinstance(argument, int):
if argument == 0:
return 0
deprecation('passing extensions and flags as constants is deprecated')
return argument
elif isinstance(argument, (tuple, list)):
return reduce(op.or_, [mapping[n] for n in set(argument) if n in mapping], 0)... | def args_to_int(mapping, argument) | Convert list of strings to an int using a mapping. | 5.492928 | 5.039479 | 1.089979 |
global compatibility
ext_handlers = options.get("ext_handlers")
if obj is None:
_pack_nil(obj, fp, options)
elif ext_handlers and obj.__class__ in ext_handlers:
_pack_ext(ext_handlers[obj.__class__](obj), fp, options)
elif isinstance(obj, bool):
_pack_boolean(obj, fp, ... | def _pack3(obj, fp, **options) | Serialize a Python object into MessagePack bytes.
Args:
obj: a Python object
fp: a .write()-supporting file-like object
Kwargs:
ext_handlers (dict): dictionary of Ext handlers, mapping a custom type
to a callable that packs an instance of the type
... | 1.976743 | 2.05599 | 0.961456 |
# Break circular dependency.
# pylint: disable=g-import-not-at-top
import pipeline
if pipeline._TEST_MODE:
return None
# Further protect against test cases that doesn't set env vars
# propertly.
if ("CURRENT_VERSION_ID" not in os.environ or
"CURRENT_MODULE_ID" not in os.environ):
logging... | def _get_task_target() | Get the default target for a pipeline task.
Current version id format is: user_defined_version.minor_version_number
Current module id is just the module's name. It could be "default"
Returns:
A complete target name is of format version.module. If module is the
default module, just version. None if target ... | 4.755438 | 4.31426 | 1.10226 |
fq_name = str(fq_name)
module_name = __name__
short_name = fq_name
if fq_name.rfind(".") >= 0:
(module_name, short_name) = (fq_name[:fq_name.rfind(".")],
fq_name[fq_name.rfind(".") + 1:])
try:
result = __import__(module_name, None, None, [short_name])
return r... | def for_name(fq_name, recursive=False) | Find class/function/method specified by its fully qualified name.
Fully qualified can be specified as:
* <module_name>.<class_name>
* <module_name>.<function_name>
* <module_name>.<class_name>.<method_name> (an unbound method will be
returned in this case).
for_name works by doing __import__ for... | 3.989815 | 4.192488 | 0.951658 |
CO_GENERATOR = 0x20
return bool(((inspect.isfunction(obj) or inspect.ismethod(obj)) and
obj.func_code.co_flags & CO_GENERATOR)) | def is_generator_function(obj) | Return true if the object is a user-defined generator function.
Generator function objects provides same attributes as functions.
See isfunction.__doc__ for attributes listing.
Adapted from Python 2.6.
Args:
obj: an object to test.
Returns:
true if the object is generator function. | 3.849411 | 5.096028 | 0.755375 |
global _TYPE_TO_ENCODER
global _TYPE_NAME_TO_DECODER
if object_type not in _TYPE_TO_ENCODER:
_TYPE_TO_ENCODER[object_type] = encoder
_TYPE_NAME_TO_DECODER[object_type.__name__] = decoder | def _register_json_primitive(object_type, encoder, decoder) | Extend what Pipeline can serialize.
Args:
object_type: type of the object.
encoder: a function that takes in an object and returns
a dict of json primitives.
decoder: inverse function of encoder. | 2.191168 | 2.34823 | 0.933115 |
k_c = d['key_string']
if isinstance(k_c, (list, tuple)):
return ndb.Key(flat=k_c)
return ndb.Key(urlsafe=d['key_string']) | def _JsonDecodeKey(d) | Json decode a ndb.Key object. | 4.506491 | 3.60482 | 1.250129 |
if type(o) in _TYPE_TO_ENCODER:
encoder = _TYPE_TO_ENCODER[type(o)]
json_struct = encoder(o)
json_struct[self.TYPE_ID] = type(o).__name__
return json_struct
return super(JsonEncoder, self).default(o) | def default(self, o) | Inherit docs. | 3.082567 | 3.205778 | 0.961566 |
if JsonEncoder.TYPE_ID not in d:
return d
type_name = d.pop(JsonEncoder.TYPE_ID)
if type_name in _TYPE_NAME_TO_DECODER:
decoder = _TYPE_NAME_TO_DECODER[type_name]
return decoder(d)
else:
raise TypeError("Invalid type %s.", type_name) | def _dict_to_obj(self, d) | Converts a dictionary of json object to a Python object. | 3.429275 | 3.268134 | 1.049307 |
stringified = pprint.saferepr(obj)
if len(stringified) > 200:
return '%s... (%d bytes)' % (stringified[:200], len(stringified))
return stringified | def _short_repr(obj) | Helper function returns a truncated repr() of an object. | 3.417651 | 3.079099 | 1.109952 |
default_bucket = app_identity.get_default_gcs_bucket_name()
if default_bucket is None:
raise Exception(
"No default cloud storage bucket has been set for this application. "
"This app was likely created before v1.9.0, please see: "
"https://cloud.google.com/appengine/docs/php/googlestorage... | def _write_json_blob(encoded_value, pipeline_id=None) | Writes a JSON encoded value to a Cloud Storage File.
This function will store the blob in a GCS file in the default bucket under
the appengine_pipeline directory. Optionally using another directory level
specified by pipeline_id
Args:
encoded_value: The encoded JSON string.
pipeline_id: A pipeline id t... | 3.59756 | 3.18468 | 1.129646 |
lookup_slots = set()
for arg in itertools.chain(args, kwargs.itervalues()):
if arg['type'] == 'slot':
lookup_slots.add(db.Key(arg['slot_key']))
slot_dict = {}
for key, slot_record in zip(lookup_slots, db.get(lookup_slots)):
if slot_record is None or slot_record.status != _SlotRecord.FILLED:
... | def _dereference_args(pipeline_name, args, kwargs) | Dereference a Pipeline's arguments that are slots, validating them.
Each argument value passed in is assumed to be a dictionary with the format:
{'type': 'value', 'value': 'serializable'} # A resolved value.
{'type': 'slot', 'slot_key': 'str() on a db.Key'} # A pending Slot.
Args:
pipeline_name: The... | 2.262472 | 1.941512 | 1.165314 |
params = {
'args': [],
'kwargs': {},
'after_all': [],
'output_slots': {},
'class_path': pipeline._class_path,
'queue_name': queue_name,
'base_path': base_path,
'backoff_seconds': pipeline.backoff_seconds,
'backoff_factor': pipeline.backoff_factor,
'max_at... | def _generate_args(pipeline, future, queue_name, base_path) | Generate the params used to describe a Pipeline's depedencies.
The arguments passed to this method may be normal values, Slot instances
(for named outputs), or PipelineFuture instances (for referring to the
default output slot).
Args:
pipeline: The Pipeline instance to generate args for.
future: The P... | 2.286628 | 2.03418 | 1.124103 |
if when is None:
return None
ms_since_epoch = float(time.mktime(when.utctimetuple()) * 1000.0)
ms_since_epoch += when.microsecond / 1000.0
return int(ms_since_epoch) | def _get_timestamp_ms(when) | Converts a datetime.datetime to integer milliseconds since the epoch.
Requires special handling to preserve microseconds.
Args:
when: A datetime.datetime instance.
Returns:
Integer time since the epoch in milliseconds. If the supplied 'when' is
None, the return value will be None. | 2.333607 | 2.426107 | 0.961873 |
if slot_dict is None:
slot_dict = {}
slot_record = slot_dict.get(slot_key)
if slot_record is None:
raise PipelineStatusError(
'Could not find data for output slot key "%s".' % slot_key)
output = {}
if slot_record.status == _SlotRecord.FILLED:
output['status'] = 'filled'
output['fi... | def _get_internal_slot(slot_key=None,
filler_pipeline_key=None,
slot_dict=None) | Gets information about a _SlotRecord for display in UI.
Args:
slot_key: The db.Key of the slot to fetch.
filler_pipeline_key: In the case the slot has not yet been filled, assume
that the given db.Key (for a _PipelineRecord) will be the filler of
the slot in the future.
slot_dict: The slot JS... | 3.270113 | 2.398784 | 1.363238 |
class_path_set = set()
for cls in _PipelineMeta._all_classes:
if cls.class_path is not None:
class_path_set.add(cls.class_path)
return sorted(class_path_set) | def get_pipeline_names() | Returns the class paths of all Pipelines defined in alphabetical order. | 4.307398 | 3.345995 | 1.28733 |
query = _PipelineRecord.all(cursor=cursor)
if class_path:
query.filter('class_path =', class_path)
query.filter('is_root_pipeline =', True)
query.order('-start_time')
root_list = query.fetch(count)
fetch_list = []
for pipeline_record in root_list:
fetch_list.append(db.Key(pipeline_record.para... | def get_root_list(class_path=None, cursor=None, count=50) | Gets a list root Pipelines.
Args:
class_path: Optional. If supplied, only return root Pipelines with the
given class_path. By default all root pipelines are returned.
cursor: Optional. When supplied, the cursor returned from the last call to
get_root_list which indicates where to pick up.
cou... | 2.601475 | 2.572713 | 1.01118 |
return [
(prefix + '/output', _BarrierHandler),
(prefix + '/run', _PipelineHandler),
(prefix + '/finalized', _PipelineHandler),
(prefix + '/cleanup', _CleanupHandler),
(prefix + '/abort', _PipelineHandler),
(prefix + '/fanout', _FanoutHandler),
(prefix + '/fanout_abort', _... | def create_handlers_map(prefix='.*') | Create new handlers map.
Args:
prefix: url prefix to use.
Returns:
list of (regexp, handler) pairs for WSGIApplication constructor. | 4.225364 | 4.509743 | 0.936941 |
if not self.filled:
raise SlotNotFilledError('Slot with name "%s", key "%s" not yet filled.'
% (self.name, self.key))
return self._value | def value(self) | Returns the current value of this slot.
Returns:
The value of the slot (a serializable Python type).
Raises:
SlotNotFilledError if the value hasn't been filled yet. | 6.987284 | 4.494816 | 1.554521 |
if not self.filled:
raise SlotNotFilledError('Slot with name "%s", key "%s" not yet filled.'
% (self.name, self.key))
return self._filler_pipeline_key.name() | def filler(self) | Returns the pipeline ID that filled this slot's value.
Returns:
A string that is the pipeline ID.
Raises:
SlotNotFilledError if the value hasn't been filled yet. | 9.302297 | 5.38614 | 1.72708 |
if not self.filled:
raise SlotNotFilledError('Slot with name "%s", key "%s" not yet filled.'
% (self.name, self.key))
return self._fill_datetime | def fill_datetime(self) | Returns when the slot was filled.
Returns:
A datetime.datetime.
Raises:
SlotNotFilledError if the value hasn't been filled yet. | 6.905684 | 4.652738 | 1.48422 |
if slot_record.status == _SlotRecord.FILLED:
self.filled = True
self._filler_pipeline_key = _SlotRecord.filler.get_value_for_datastore(
slot_record)
self._fill_datetime = slot_record.fill_time
self._value = slot_record.value | def _set_value(self, slot_record) | Sets the value of this slot based on its corresponding _SlotRecord.
Does nothing if the slot has not yet been filled.
Args:
slot_record: The _SlotRecord containing this Slot's value. | 6.807661 | 6.026471 | 1.129626 |
for name, slot_key in already_defined.iteritems():
if not isinstance(slot_key, db.Key):
slot_key = db.Key(slot_key)
slot = self._output_dict.get(name)
if slot is None:
if self._strict:
raise UnexpectedPipelineError(
'Inherited output named "%s" must be... | def _inherit_outputs(self,
pipeline_name,
already_defined,
resolve_outputs=False) | Inherits outputs from a calling Pipeline.
Args:
pipeline_name: The Pipeline class name (used for debugging).
already_defined: Maps output name to stringified db.Key (of _SlotRecords)
of any exiting output slots to be inherited by this future.
resolve_outputs: When True, this method will d... | 2.993275 | 2.621855 | 1.141663 |
pipeline_record = _pipeline_record
# Support pipeline IDs and idempotence_keys that are not unicode.
if not isinstance(pipeline_id, unicode):
try:
pipeline_id = pipeline_id.encode('utf-8')
except UnicodeDecodeError:
pipeline_id = hashlib.sha1(pipeline_id).hexdigest()
p... | def from_id(cls, pipeline_id, resolve_outputs=True, _pipeline_record=None) | Returns an instance corresponding to an existing Pipeline.
The returned object will have the same properties a Pipeline does while
it's running synchronously (e.g., like what it's first allocated), allowing
callers to inspect caller arguments, outputs, fill slots, complete the
pipeline, abort, retry, e... | 3.821875 | 3.774747 | 1.012485 |
if not idempotence_key:
idempotence_key = uuid.uuid4().hex
elif not isinstance(idempotence_key, unicode):
try:
idempotence_key.encode('utf-8')
except UnicodeDecodeError:
idempotence_key = hashlib.sha1(idempotence_key).hexdigest()
pipeline_key = db.Key.from_path(_Pipel... | def start(self,
idempotence_key='',
queue_name='default',
base_path='/_ah/pipeline',
return_task=False,
countdown=None,
eta=None) | Starts a new instance of this pipeline.
Args:
idempotence_key: The ID to use for this Pipeline and throughout its
asynchronous workflow to ensure the operations are idempotent. If
empty a starting key will be automatically assigned.
queue_name: What queue this Pipeline's workflow should... | 3.881828 | 3.786742 | 1.02511 |
if not self.async:
raise UnexpectedPipelineError(
'May only call retry() method for asynchronous pipelines.')
if self.try_cancel():
self._context.transition_retry(self._pipeline_key, retry_message)
return True
else:
return False | def retry(self, retry_message='') | Forces a currently running asynchronous pipeline to retry.
Note this may not be called by synchronous or generator pipelines. Those
must instead raise the 'Retry' exception during execution.
Args:
retry_message: Optional message explaining why the retry happened.
Returns:
True if the Pipe... | 10.515561 | 7.471988 | 1.407331 |
# TODO: Use thread-local variable to enforce that this is not called
# while a pipeline is executing in the current thread.
if (self.async and self._root_pipeline_key == self._pipeline_key and
not self.try_cancel()):
# Handle the special case where the root pipeline is async and thus
... | def abort(self, abort_message='') | Mark the entire pipeline up to the root as aborted.
Note this should only be called from *outside* the context of a running
pipeline. Synchronous and generator pipelines should raise the 'Abort'
exception to cause this behavior during execution.
Args:
abort_message: Optional message explaining w... | 8.032084 | 6.793746 | 1.182276 |
if isinstance(name_or_slot, basestring):
slot = getattr(self.outputs, name_or_slot)
elif isinstance(name_or_slot, Slot):
slot = name_or_slot
else:
raise UnexpectedPipelineError(
'Could not fill invalid output name: %r' % name_or_slot)
if not slot._exists:
raise Sl... | def fill(self, name_or_slot, value) | Fills an output slot required by this Pipeline.
Args:
name_or_slot: The name of the slot (a string) or Slot record to fill.
value: The serializable value to assign to this slot.
Raises:
UnexpectedPipelineError if the Slot no longer exists. SlotNotDeclaredError
if trying to output to a ... | 4.184992 | 3.192031 | 1.311075 |
if _TEST_MODE:
logging.info(
'New status for %s#%s: message=%r, console_url=%r, status_links=%r',
self, self.pipeline_id, message, console_url, status_links)
return
status_key = db.Key.from_path(_StatusRecord.kind(), self.pipeline_id)
root_pipeline_key = db.Key.from_pat... | def set_status(self, message=None, console_url=None, status_links=None) | Sets the current status of this pipeline.
This method is purposefully non-transactional. Updates are written to the
datastore immediately and overwrite all existing statuses.
Args:
message: (optional) Overall status message.
console_url: (optional) Relative URL to use for the "console" of this... | 2.531543 | 2.416037 | 1.047808 |
# TODO: Enforce that all outputs expected by this async pipeline were
# filled before this complete() function was called. May required all
# async functions to declare their outputs upfront.
if not self.async:
raise UnexpectedPipelineError(
'May only call complete() method for asyn... | def complete(self, default_output=None) | Marks this asynchronous Pipeline as complete.
Args:
default_output: What value the 'default' output slot should be assigned.
Raises:
UnexpectedPipelineError if the slot no longer exists or this method was
called for a pipeline that is not async. | 16.434467 | 10.390821 | 1.581633 |
# TODO: Support positional parameters.
if not self.async:
raise UnexpectedPipelineError(
'May only call get_callback_url() method for asynchronous pipelines.')
kwargs['pipeline_id'] = self._pipeline_key.name()
params = urllib.urlencode(sorted(kwargs.items()))
return '%s/callback... | def get_callback_url(self, **kwargs) | Returns a relative URL for invoking this Pipeline's callback method.
Args:
kwargs: Dictionary mapping keyword argument names to single values that
should be passed to the callback when it is invoked.
Raises:
UnexpectedPipelineError if this is invoked on pipeline that is not async. | 6.090443 | 4.438367 | 1.372226 |
if not self.async:
raise UnexpectedPipelineError(
'May only call get_callback_task() method for asynchronous pipelines.')
params = kwargs.get('params', {})
kwargs['params'] = params
params['pipeline_id'] = self._pipeline_key.name()
kwargs['url'] = self.base_path + '/callback'
... | def get_callback_task(self, *args, **kwargs) | Returns a task for calling back this Pipeline.
Args:
params: Keyword argument containing a dictionary of key/value pairs
that will be passed to the callback when it is executed.
args, kwargs: Passed to the taskqueue.Task constructor. Use these
arguments to set the task name (for idempot... | 5.104507 | 4.177999 | 1.221759 |
status = 'successful'
if self.was_aborted:
status = 'aborted'
app_id = os.environ['APPLICATION_ID']
shard_index = app_id.find('~')
if shard_index != -1:
app_id = app_id[shard_index+1:]
param_dict = {
'status': status,
'app_id': app_id,
'class_path': sel... | def send_result_email(self, sender=None) | Sends an email to admins indicating this Pipeline has completed.
For developer convenience. Automatically called from finalized for root
Pipelines that do not override the default action.
Args:
sender: (optional) Override the sender's email address. | 3.310222 | 3.265927 | 1.013563 |
if self._root_pipeline_key is None:
raise UnexpectedPipelineError(
'Could not cleanup Pipeline with unknown root pipeline ID.')
if not self.is_root:
return
task = taskqueue.Task(
params=dict(root_pipeline_key=self._root_pipeline_key),
url=self.base_path + '/cleanup... | def cleanup(self) | Clean up this Pipeline and all Datastore records used for coordination.
Only works when called on a root pipeline. Child pipelines will ignore
calls to this method.
After this method is called, Pipeline.from_id() and related status
methods will return inconsistent or missing results. This method is
... | 5.561945 | 4.706159 | 1.181844 |
if _TEST_MODE:
logging.info(
'Setting runtime parameters for %s#%s: %r',
self, self.pipeline_id, kwargs)
return self
if self.pipeline_id is not None:
raise UnexpectedPipelineError(
'May only call with_params() on a Pipeline that has not yet '
'been... | def with_params(self, **kwargs) | Modify various execution parameters of a Pipeline before it runs.
This method has no effect in test mode.
Args:
kwargs: Attributes to modify on this Pipeline instance before it has
been executed.
Returns:
This Pipeline instance, for easy chaining. | 4.502721 | 4.319901 | 1.04232 |
# Do not traverse the class hierarchy fetching the class path attribute.
found = cls.__dict__.get('_class_path')
if found is not None:
return
# Do not set the _class_path for the base-class, otherwise all children's
# lookups for _class_path will fall through and return 'Pipeline' above.... | def _set_class_path(cls, module_dict=sys.modules) | Sets the absolute path to this class as a string.
Used by the Pipeline API to reconstruct the Pipeline sub-class object
at execution time instead of passing around a serialized function.
Args:
module_dict: Used for testing. | 5.67066 | 5.556991 | 1.020455 |
self._context = context
self._pipeline_key = pipeline_key
self._root_pipeline_key = root_pipeline_key
self._result_status = result_status
self.outputs = outputs | def _set_values_internal(self,
context,
pipeline_key,
root_pipeline_key,
outputs,
result_status) | Sets the user-visible values provided as an API by this class.
Args:
context: The _PipelineContext used for this Pipeline.
pipeline_key: The db.Key of this pipeline.
root_pipeline_key: The db.Key of the root pipeline.
outputs: The PipelineFuture for this pipeline.
result_status: The r... | 2.254473 | 2.119153 | 1.063856 |
logging.debug('Callback %s(*%s, **%s)#%s with params: %r',
self._class_path, _short_repr(self.args),
_short_repr(self.kwargs), self._pipeline_key.name(), kwargs)
return self.callback(**kwargs) | def _callback_internal(self, kwargs) | Used to execute callbacks on asynchronous pipelines. | 7.201515 | 6.624517 | 1.0871 |
self._set_values_internal(
context, pipeline_key, root_pipeline_key, caller_output,
_PipelineRecord.RUN)
logging.debug('Running %s(*%s, **%s)#%s',
self._class_path, _short_repr(self.args),
_short_repr(self.kwargs), self._pipeline_key.name())
return se... | def _run_internal(self,
context,
pipeline_key,
root_pipeline_key,
caller_output) | Used by the Pipeline evaluator to execute this Pipeline. | 5.137721 | 4.865238 | 1.056006 |
result_status = _PipelineRecord.RUN
if aborted:
result_status = _PipelineRecord.ABORTED
self._set_values_internal(
context, pipeline_key, root_pipeline_key, caller_output, result_status)
logging.debug('Finalizing %s(*%r, **%r)#%s',
self._class_path, _short_repr(self... | def _finalized_internal(self,
context,
pipeline_key,
root_pipeline_key,
caller_output,
aborted) | Used by the Pipeline evaluator to finalize this Pipeline. | 5.260597 | 4.932958 | 1.066418 |
if cls._local._activated:
cls._local._in_order_futures.add(future) | def _add_future(cls, future) | Adds a future to the list of in-order futures thus far.
Args:
future: The future to add to the list. | 15.162353 | 11.467258 | 1.32223 |
if not hasattr(cls._local, '_in_order_futures'):
cls._local._in_order_futures = set()
cls._local._activated = False | def _thread_init(cls) | Ensure thread local is initialized. | 8.647036 | 6.582638 | 1.313612 |
base_path, unused = (environ['PATH_INFO'].rsplit('/', 1) + [''])[:2]
return cls(
environ['HTTP_X_APPENGINE_TASKNAME'],
environ['HTTP_X_APPENGINE_QUEUENAME'],
base_path) | def from_environ(cls, environ=os.environ) | Constructs a _PipelineContext from the task queue environment. | 4.197647 | 3.537248 | 1.186699 |
if not isinstance(filler_pipeline_key, db.Key):
filler_pipeline_key = db.Key(filler_pipeline_key)
if _TEST_MODE:
slot._set_value_test(filler_pipeline_key, value)
else:
encoded_value = json.dumps(value,
sort_keys=True,
... | def fill_slot(self, filler_pipeline_key, slot, value) | Fills a slot, enqueueing a task to trigger pending barriers.
Args:
filler_pipeline_key: db.Key or stringified key of the _PipelineRecord
that filled this slot.
slot: The Slot instance to fill.
value: The serializable value to assign.
Raises:
UnexpectedPipelineError if the _Slot... | 4.202594 | 3.970735 | 1.058392 |
def txn():
pipeline_record = db.get(root_pipeline_key)
if pipeline_record is None:
logging.warning(
'Tried to abort root pipeline ID "%s" but it does not exist.',
root_pipeline_key.name())
raise db.Rollback()
if pipeline_record.status == _PipelineRecord... | def begin_abort(self, root_pipeline_key, abort_message) | Kicks off the abort process for a root pipeline and all its children.
Args:
root_pipeline_key: db.Key of the root pipeline to abort.
abort_message: Message explaining why the abort happened, only saved
into the root pipeline.
Returns:
True if the abort signal was sent successfully;... | 2.480379 | 2.267797 | 1.09374 |
if not isinstance(root_pipeline_key, db.Key):
root_pipeline_key = db.Key(root_pipeline_key)
# NOTE: The results of this query may include _PipelineRecord instances
# that are not actually "reachable", meaning you cannot get to them by
# starting at the root pipeline and following "fanned_out"... | def continue_abort(self,
root_pipeline_key,
cursor=None,
max_to_notify=_MAX_ABORTS_TO_BEGIN) | Sends the abort signal to all children for a root pipeline.
Args:
root_pipeline_key: db.Key of the root pipeline to abort.
cursor: The query cursor for enumerating _PipelineRecords when inserting
tasks to cause child pipelines to terminate.
max_to_notify: Used for testing. | 4.569677 | 4.36583 | 1.046691 |
# Adjust all pipeline output keys for this Pipeline to be children of
# the _PipelineRecord, that way we can write them all and submit in a
# single transaction.
for name, slot in pipeline.outputs._output_dict.iteritems():
slot.key = db.Key.from_path(
*slot.key.to_path(), **dict(par... | def start(self, pipeline, return_task=True, countdown=None, eta=None) | Starts a pipeline.
Args:
pipeline: Pipeline instance to run.
return_task: When True, do not submit the task to start the pipeline
but instead return it for someone else to enqueue.
countdown: Time in seconds into the future that this Task should execute.
Defaults to zero.
et... | 4.585701 | 4.634648 | 0.989439 |
result = []
blocking_slot_keys = list(blocking_slot_keys)
barrier = _BarrierRecord(
parent=child_pipeline_key,
key_name=purpose,
target=child_pipeline_key,
root_pipeline=root_pipeline_key,
blocking_slots=blocking_slot_keys)
result.append(barrier)
for ... | def _create_barrier_entities(root_pipeline_key,
child_pipeline_key,
purpose,
blocking_slot_keys) | Creates all of the entities required for a _BarrierRecord.
Args:
root_pipeline_key: The root pipeline this is part of.
child_pipeline_key: The pipeline this barrier is for.
purpose: _BarrierRecord.START or _BarrierRecord.FINALIZE.
blocking_slot_keys: Set of db.Keys corresponding to _SlotRec... | 2.572696 | 2.179284 | 1.180524 |
if isinstance(e, Retry):
retry_message = str(e)
logging.warning('User forced retry for pipeline ID "%s" of %r: %s',
pipeline_key.name(), pipeline_func, retry_message)
self.transition_retry(pipeline_key, retry_message)
elif isinstance(e, Abort):
abort_message = ... | def handle_run_exception(self, pipeline_key, pipeline_func, e) | Handles an exception raised by a Pipeline's user code.
Args:
pipeline_key: The pipeline that raised the error.
pipeline_func: The class path name of the Pipeline that was running.
e: The exception that was raised.
Returns:
True if the exception should be re-raised up through the callin... | 2.898162 | 2.963789 | 0.977857 |
def txn():
pipeline_record = db.get(pipeline_key)
if pipeline_record is None:
logging.warning('Pipeline ID "%s" cannot be marked as run. '
'Does not exist.', pipeline_key.name())
raise db.Rollback()
if pipeline_record.status != _PipelineRecord.WAITING:
... | def transition_run(self,
pipeline_key,
blocking_slot_keys=None,
fanned_out_pipelines=None,
pipelines_to_run=None) | Marks an asynchronous or generator pipeline as running.
Does nothing if the pipeline is no longer in a runnable state.
Args:
pipeline_key: The db.Key of the _PipelineRecord to update.
blocking_slot_keys: List of db.Key instances that this pipeline's
finalization barrier should wait on in a... | 4.844608 | 4.264215 | 1.136108 |
def txn():
pipeline_record = db.get(pipeline_key)
if pipeline_record is None:
logging.warning(
'Tried to mark pipeline ID "%s" as complete but it does not exist.',
pipeline_key.name())
raise db.Rollback()
if pipeline_record.status not in (
_Pi... | def transition_complete(self, pipeline_key) | Marks the given pipeline as complete.
Does nothing if the pipeline is no longer in a state that can be completed.
Args:
pipeline_key: db.Key of the _PipelineRecord that has completed. | 3.227152 | 2.629639 | 1.227222 |
def txn():
pipeline_record = db.get(pipeline_key)
if pipeline_record is None:
logging.warning(
'Tried to retry pipeline ID "%s" but it does not exist.',
pipeline_key.name())
raise db.Rollback()
if pipeline_record.status not in (
_PipelineRecor... | def transition_retry(self, pipeline_key, retry_message) | Marks the given pipeline as requiring another retry.
Does nothing if all attempts have been exceeded.
Args:
pipeline_key: db.Key of the _PipelineRecord that needs to be retried.
retry_message: User-supplied message indicating the reason for the retry. | 2.991238 | 2.795133 | 1.07016 |
pipeline_id = self.request.get('pipeline_id')
if not pipeline_id:
raise _CallbackTaskError('"pipeline_id" parameter missing.')
pipeline_key = db.Key.from_path(_PipelineRecord.kind(), pipeline_id)
pipeline_record = db.get(pipeline_key)
if pipeline_record is None:
raise _CallbackTask... | def run_callback(self) | Runs the callback for the pipeline specified in the request.
Raises:
_CallbackTaskError if something was wrong with the request parameters. | 2.795971 | 2.653804 | 1.053571 |
import os
import sys
all_paths = os.environ.get('PYTHONPATH').split(os.pathsep)
for path_dir in all_paths:
dev_appserver_path = os.path.join(path_dir, 'dev_appserver.py')
if os.path.exists(dev_appserver_path):
logging.debug('Found appengine SDK on path!')
google_appengine = os.path.dirnam... | def _fix_path() | Finds the google_appengine directory and fixes Python imports to use it. | 3.79623 | 3.405303 | 1.114799 |
if hasattr(self, '_params_decoded'):
return self._params_decoded
if self.params_blob is not None:
value_encoded = self.params_blob.open().read()
else:
value_encoded = self.params_text
value = json.loads(value_encoded, cls=util.JsonDecoder)
if isinstance(value, dict):
k... | def params(self) | Returns the dictionary of parameters for this Pipeline. | 3.312776 | 3.291795 | 1.006374 |
if hasattr(self, '_value_decoded'):
return self._value_decoded
if self.value_blob is not None:
encoded_value = self.value_blob.open().read()
else:
encoded_value = self.value_text
self._value_decoded = json.loads(encoded_value, cls=util.JsonDecoder)
return self._value_decoded | def value(self) | Returns the value of this Slot. | 3.344494 | 3.351375 | 0.997947 |
barrier_index_path = barrier_index_key.to_path()
# Pick out the items from the _BarrierIndex key path that we need to
# construct the _BarrierRecord key path.
(pipeline_kind, dependent_pipeline_id,
unused_kind, purpose) = barrier_index_path[-4:]
barrier_record_path = (
pipeline_k... | def to_barrier_key(cls, barrier_index_key) | Converts a _BarrierIndex key to a _BarrierRecord key.
Args:
barrier_index_key: db.Key for a _BarrierIndex entity.
Returns:
db.Key for the corresponding _BarrierRecord entity. | 5.902054 | 5.802835 | 1.017098 |
# Check the page number is valid.
if page <= self.page_count:
raise ValueError("Page {0:d} has already started, cannot mark used labels now.".format(page))
# Add these to any existing labels marked as used.
used = self._used.get(page, set())
for row, column ... | def partial_page(self, page, used_labels) | Allows a page to be marked as already partially used so you can
generate a PDF to print on the remaining labels.
Parameters
----------
page: positive integer
The page number to mark as partially used. The page must not have
already been started, i.e., for page 1 ... | 3.64602 | 3.171363 | 1.14967 |
self._current_page = Drawing(*self._pagesize)
if self._bgimage:
self._current_page.add(self._bgimage)
self._pages.append(self._current_page)
self.page_count += 1
self._position = [1, 0] | def _new_page(self) | Helper function to start a new page. Not intended for external use. | 4.119328 | 3.796548 | 1.085019 |
# Special case for the very first label.
if self.page_count == 0:
self._new_page()
# Filled up a page.
elif self._position == self._numlabels:
self._new_page()
# Filled up a row.
elif self._position[1] == self.specs.columns:
... | def _next_label(self) | Helper method to move to the next label. Not intended for external use.
This does not increment the label_count attribute as the next label may
not be usable (it may have been marked as missing through
partial_pages). See _next_unused_label for generally more useful method. | 4.251585 | 3.944029 | 1.07798 |
self._next_label()
# This label may be missing.
if self.page_count in self._used:
# Keep try while the label is missing.
missing = self._used.get(self.page_count, set())
while tuple(self._position) in missing:
# Throw the missing info... | def _next_unused_label(self) | Helper method to move to the next unused label. Not intended for external use.
This method will shade in any missing labels if desired, and will
increment the label_count attribute once a suitable label position has
been found. | 6.028337 | 4.985713 | 1.209122 |
# Calculate the left edge of the label.
left = self.specs.left_margin
left += (self.specs.label_width * (self._position[1] - 1))
if self.specs.column_gap:
left += (self.specs.column_gap * (self._position[1] - 1))
left *= mm
# And the bottom.
... | def _calculate_edges(self) | Calculate edges of the current label. Not intended for external use. | 2.970569 | 2.69391 | 1.102698 |
# Start a drawing for the whole label.
label = Drawing(float(self._lw), float(self._lh))
label.add(self._clip_label)
# Fill with a rectangle; the clipping path will take care of the borders.
r = shapes.Rect(0, 0, float(self._lw), float(self._lh))
r.fillColor = s... | def _shade_missing_label(self) | Helper method to shade a missing label. Not intended for external use. | 5.771303 | 5.469357 | 1.055207 |
# Sanity check.
if not self.shade_missing:
return
# Run through each missing label left in the current page and shade it.
missing = self._used.get(self.page_count, set())
for position in missing:
self._position = position
self._shade_... | def _shade_remaining_missing(self) | Helper method to shade any missing labels remaining on the current
page. Not intended for external use.
Note that this will modify the internal _position attribute and should
therefore only be used once all the 'real' labels have been drawn. | 8.91956 | 6.495528 | 1.373185 |
# Start a drawing for the whole label.
label = Drawing(float(self._lw), float(self._lh))
label.add(self._clip_label)
# And one for the available area (i.e., after padding).
available = Drawing(float(self._dw), float(self._dh))
available.add(self._clip_drawing)
... | def _draw_label(self, obj, count) | Helper method to draw on the current label. Not intended for external use. | 5.590129 | 5.461792 | 1.023497 |
# If we can convert it to an int, do so and use the itertools.repeat()
# method to create an infinite iterator from it. Otherwise, assume it
# is an iterable or sequence.
try:
count = int(count)
except TypeError:
pass
else:
cou... | def add_labels(self, objects, count=1) | Add multiple labels to the sheet.
Parameters
----------
objects: iterable
An iterable of the objects to add. Each of these will be passed to
the add_label method. Note that if this is a generator it will be
consumed.
count: positive integer or iterabl... | 4.234927 | 4.135586 | 1.024021 |
# Shade any remaining missing labels if desired.
self._shade_remaining_missing()
# Create a canvas.
canvas = Canvas(filelike, pagesize=self._pagesize)
# Render each created page onto the canvas.
for page in self._pages:
renderPDF.draw(page, canvas, ... | def save(self, filelike) | Save the file as a PDF.
Parameters
----------
filelike: path or file-like object
The filename or file-like object to save the labels under. Any
existing contents will be overwritten. | 6.395486 | 5.670358 | 1.12788 |
# Check the page number.
if page < 1 or page > self.page_count:
raise ValueError("Invalid page number; should be between 1 and {0:d}.".format(self.page_count))
# Shade any remaining missing labels if desired.
self._shade_remaining_missing()
# Rendering to a... | def preview(self, page, filelike, format='png', dpi=72, background_colour=0xFFFFFF) | Render a preview image of a page.
Parameters
----------
page: positive integer
Which page to render. Must be in the range [1, page_count]
filelike: path or file-like object
Can be a filename as a string, a Python file object, or something
which behave... | 3.961828 | 3.943706 | 1.004595 |
# Check the page number.
if page < 1 or page > self.page_count:
raise ValueError("Invalid page number; should be between 1 and {0:d}.".format(self.page_count))
# Shade any remaining missing labels if desired.
self._shade_remaining_missing()
# Rendering to a... | def preview_string(self, page, format='png', dpi=72, background_colour=0xFFFFFF) | Render a preview image of a page as a string.
Parameters
----------
page: positive integer
Which page to render. Must be in the range [1, page_count]
format: string
The image format to use for the preview. ReportLab uses the Python
Imaging Library (PI... | 3.978232 | 3.957016 | 1.005362 |
boxes = {}
# Check the parameters.
if mode not in ('fraction', 'actual'):
raise ValueError("Unknown mode {0}.".format(mode))
if output not in ('dict', 'json'):
raise ValueError("Unknown output {0}.".format(output))
# Iterate over the rows.
... | def bounding_boxes(self, mode='fraction', output='dict') | Get the bounding boxes of the labels on a page.
Parameters
----------
mode: 'fraction', 'actual'
If 'fraction', the bounding boxes are expressed as a fraction of the
height and width of the sheet. If 'actual', they are the actual
position of the labels in mil... | 2.05872 | 1.957114 | 1.051916 |
others = []
spans = [i for i in findBalanced(text, open, close)]
spanscopy = copy(spans)
for i in range(len(spans)):
start, end = spans[i]
o = text[start:end]
ol = o.lower()
if 'vaata|' in ol or 'wikitable' in ol:
spanscopy.remove(spans[i])
c... | def templatesCollector(text, open, close) | leaves related articles and wikitables in place | 5.370447 | 5.229371 | 1.026978 |
seen_layers = set()
for k, v in kwargs.items():
if k not in LEGAL_ARGUMENTS:
raise ValueError('Illegal argument <{0}>!'.format(k))
if k in AESTHETICS:
if v in seen_layers:
raise ValueError('Layer <{0}> mapped for more than a single aesthetic!'.format(... | def assert_legal_arguments(kwargs) | Assert that PrettyPrinter arguments are correct.
Raises
------
ValueError
In case there are unknown arguments or a single layer is mapped to more than one aesthetic. | 2.895252 | 2.551737 | 1.13462 |
aesthetics = {}
values = {}
for aes in AESTHETICS:
if aes in kwargs:
aesthetics[aes] = kwargs[aes]
val_name = AES_VALUE_MAP[aes]
# map the user-provided CSS value or use the default
values[aes] = kwargs.get(val_name, DEFAULT_VALUE_MAP[aes])
re... | def parse_arguments(kwargs) | Function that parses PrettyPrinter arguments.
Detects which aesthetics are mapped to which layers
and collects user-provided values.
Parameters
----------
kwargs: dict
The keyword arguments to PrettyPrinter.
Returns
-------
dict, dict
First dictionary is aesthetic to la... | 4.540017 | 3.871659 | 1.172628 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.