_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q4300 | ModuleGraph.findModuleOfName | train | def findModuleOfName(self, dotted_name, level, filename, extrapath=None):
"""Given a fully qualified name, find what module contains it."""
if dotted_name.endswith('.*'):
return dotted_name[:-2]
name = dotted_name
# extrapath is None only in a couple of test cases; in real life it's
# always present
if level and level > 1 and extrapath:
# strip trailing path bits for each extra level to account for
# relative imports
# from . import X has level == 1 and nothing is stripped (the level | python | {
"resource": ""
} |
q4301 | ModuleGraph.isModule | train | def isModule(self, dotted_name, extrapath=None):
"""Is ``dotted_name`` the name of a module?"""
try:
return self._module_cache[(dotted_name, extrapath)]
except KeyError:
pass
if dotted_name in sys.modules or dotted_name in self.builtin_modules:
return dotted_name
filename = dotted_name.replace('.', os.path.sep)
if extrapath:
for ext in self._exts:
candidate = os.path.join(extrapath, filename) + ext
if os.path.exists(candidate):
modname = self.filenameToModname(candidate)
self._module_cache[(dotted_name, extrapath)] = modname
return modname
try:
return self._module_cache[(dotted_name, None)]
except KeyError:
pass
for dir in self.path:
if os.path.isfile(dir):
if dir.endswith('.egg-info'):
# distribute creates a setuptools-blah-blah.egg-info
# that ends up in sys.path
continue
try:
zf = zipfile.ZipFile(dir)
except zipfile.BadZipfile:
self.warn(dir, "%s: not a directory or zip file", dir)
continue
names = zf.namelist()
for ext in self._exts:
candidate = filename + ext
| python | {
"resource": ""
} |
q4302 | ModuleGraph.isPackage | train | def isPackage(self, dotted_name, extrapath=None):
"""Is ``dotted_name`` the name of a package?"""
| python | {
"resource": ""
} |
q4303 | ModuleGraph.packageOf | train | def packageOf(self, dotted_name, packagelevel=None):
"""Determine the package that contains ``dotted_name``."""
if '.' not in dotted_name:
return dotted_name
if not self.isPackage(dotted_name):
| python | {
"resource": ""
} |
q4304 | ModuleGraph.listModules | train | def listModules(self):
"""Return an alphabetical list of all modules."""
modules = list(self.modules.items())
| python | {
"resource": ""
} |
q4305 | ModuleGraph.packageGraph | train | def packageGraph(self, packagelevel=None):
"""Convert a module graph to a package graph."""
packages = {}
for module in self.listModules():
package_name = self.packageOf(module.modname, packagelevel)
if package_name not in packages:
dirname = os.path.dirname(module.filename)
| python | {
"resource": ""
} |
q4306 | ModuleGraph.collapseCycles | train | def collapseCycles(self):
"""Create a graph with cycles collapsed.
Collapse modules participating in a cycle to a single node.
"""
# This algorithm determines Strongly Connected Components. Look it up.
# It is adapted to suit our data structures.
# Phase 0: prepare the graph
imports = {}
for u in self.modules:
imports[u] = set()
for v in self.modules[u].imports:
if v in self.modules: # skip external dependencies
imports[u].add(v)
# Phase 1: order the vertices
visited = {}
for u in self.modules:
visited[u] = False
order = []
def visit1(u):
visited[u] = True
for v in imports[u]:
if not visited[v]:
visit1(v)
order.append(u)
for u in self.modules:
if not visited[u]:
visit1(u)
order.reverse()
# Phase 2: compute the inverse graph
revimports = {}
for u in self.modules:
revimports[u] = set()
for u in self.modules:
for v in imports[u]:
revimports[v].add(u)
# Phase 3: determine the strongly connected components
components = {}
component_of = {}
for u in self.modules:
visited[u] = False
def visit2(u):
visited[u] = True
component.append(u)
for v in revimports[u]:
if not visited[v]:
visit2(v)
for | python | {
"resource": ""
} |
q4307 | ModuleGraph.printImportedNames | train | def printImportedNames(self):
"""Produce a report of imported names."""
for module in self.listModules():
print("%s:" % module.modname)
| python | {
"resource": ""
} |
q4308 | ModuleGraph.printImports | train | def printImports(self):
"""Produce a report of dependencies."""
for module in self.listModules():
print("%s:" % module.label)
if self.external_dependencies:
imports = list(module.imports)
else:
| python | {
"resource": ""
} |
q4309 | ModuleGraph.printUnusedImports | train | def printUnusedImports(self):
"""Produce a report of unused imports."""
for module in self.listModules():
names = [(unused.lineno, unused.name)
for unused in module.unused_names]
names.sort()
for lineno, name in names:
if not self.all_unused:
line = linecache.getline(module.filename, lineno)
| python | {
"resource": ""
} |
q4310 | ModuleGraph.printDot | train | def printDot(self):
"""Produce a dependency graph in dot format."""
print("digraph ModuleDependencies {")
print(" node[shape=box];")
allNames = set()
nameDict = {}
for n, module in enumerate(self.listModules()):
module._dot_name = "mod%d" % n
nameDict[module.modname] = module._dot_name
print(" %s[label=\"%s\"];" % (module._dot_name,
quote(module.label)))
allNames |= module.imports
print(" node[style=dotted];")
if self.external_dependencies:
myNames = set(self.modules)
extNames = list(allNames - myNames)
| python | {
"resource": ""
} |
q4311 | quote | train | def quote(text):
"""encode html entities"""
text = unicode(text)
return text.translate({
ord('&'): u'&',
ord('<'): u'<',
| python | {
"resource": ""
} |
q4312 | _create_tags | train | def _create_tags(ctx):
"create all classes and put them in ctx"
for (tag, info) in _TAGS.items():
class_name = tag.title()
quote_, compact, self_closing, docs = info
def __init__(self, *childs, **attrs):
TagBase.__init__(self, childs, attrs)
cls = type(class_name, (TagBase,), {
| python | {
"resource": ""
} |
q4313 | tag_from_element | train | def tag_from_element(el):
"""
Convert an Element into a Tag.
``el`` is an instance of ``Element``. Returns an instance of the
corresponding subclass of ``TagBase``.
"""
tag = el.tag
namespace = None
if tag.startswith('{'):
# Strip namespace of the form "{namespace}tag"
| python | {
"resource": ""
} |
q4314 | html_to_tags | train | def html_to_tags(code):
"""
Convert HTML code to tags.
``code`` is a string containing HTML code. The return value is a
list of corresponding instances of ``TagBase``.
"""
| python | {
"resource": ""
} |
q4315 | HTMLTranslator._init_math_handler | train | def _init_math_handler(self):
"""
Parse math configuration and set up math handler.
"""
fields = self.settings.math_output.split(None, 1)
name = fields[0].lower()
option = fields[1] if len(fields) > 1 else None
if name == 'html':
option = self.settings.math_css or option
self.math_handler = HTMLMathHandler(css_filename=option)
elif name == 'mathml':
if option:
raise ValueError(('Math handler "%s" does not support ' +
'option "%s".') % (name, option))
self.math_handler = MathMLMathHandler()
elif name == 'mathjax':
# The MathJax handler can be configured via different ways:
#
# - By passing an additional JS url to "--math-output"
# (to stay backwards-compatible with docutils)
#
# - By using "--mathjax-opts" (to stay backwards compatible
# with the previous html5css3 mathjax postprocessor)
#
# - By using "--mathjax-url" and "--mathjax-config" (the
# preferred way)
js_url = option
| python | {
"resource": ""
} |
q4316 | HTMLTranslator.append_default_stylesheets | train | def append_default_stylesheets(self):
"""
Appends the default styles defined on the translator settings.
"""
| python | {
"resource": ""
} |
q4317 | repr_args | train | def repr_args(args):
"""formats a list of function arguments prettily but as working code
(kwargs are tuples (argname, argvalue)
"""
res = []
for x in args:
if isinstance(x, tuple) and len(x) == 2:
key, value = x
| python | {
"resource": ""
} |
q4318 | repr_arg | train | def repr_arg(d):
"""formats a function argument prettily but as working code
unicode encodable as ascii is formatted as str"""
if isinstance(d, dict):
# if d can be expressed in key=value syntax:
return "{%s}" % ", ".join(
"%s: %s" % (repr_arg(k), repr_arg(v)) for k, v in d.items())
if isinstance(d, list):
| python | {
"resource": ""
} |
q4319 | str_args | train | def str_args(args):
"""formats a list of function arguments prettily not as code
(kwargs are tuples (argname, argvalue)
"""
res = []
for x in args:
if isinstance(x, tuple) and len(x) == 2:
key, value = x
| python | {
"resource": ""
} |
q4320 | str_arg | train | def str_arg(d):
"""formats a function argument prettily not as code
dicts are expressed in {key=value} syntax
strings are formatted using str in quotes not repr"""
if not d:
return None
if isinstance(d, dict):
if len(d) == 2 and d.get('type') == 'text' and 'value' in d:
return str_arg(d['value'])
if len(d) == 2 and d.get('type') == 'text' and 'subkey' in d:
return ".%s" % d['subkey']
if d.get('type') == 'module':
return None
| python | {
"resource": ""
} |
q4321 | asyncPipeHash | train | def asyncPipeHash(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously hashes the given text. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items or strings
Returns
-------
_OUTPUT : twisted.internet.defer.Deferred generator of hashed strings
"""
splits = | python | {
"resource": ""
} |
q4322 | pipe_tail | train | def pipe_tail(context=None, _INPUT=None, conf=None, **kwargs):
"""Returns a specified number of items from the bottom of a feed.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
kwargs -- terminal, if the truncation value is wired in
conf : count -- length of the truncated feed, if specified literally
| python | {
"resource": ""
} |
q4323 | get_graph_component | train | def get_graph_component(graph):
""" Identify strongly connected components in a graph using
Tarjan's algorithm.
graph should be a dictionary mapping node names to
lists of successor nodes.
"""
components = map(partial(_visit, graph=graph), graph)
| python | {
"resource": ""
} |
q4324 | pipe_xpathfetchpage | train | def pipe_xpathfetchpage(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches the content of a given website as DOM nodes or a
string. Loopable.
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : dict
URL -- url object contain the URL to download
xpath -- xpath to extract
html5 -- use html5 parser?
useAsString -- emit items as string?
TODOS:
- don't retrieve pages larger than 1.5MB
- don't retrieve if page is not indexable.
Yields
------
_OUTPUT : items
"""
conf = DotDict(conf)
urls = utils.listize(conf['URL'])
for item in _INPUT:
for item_url in urls:
url = utils.get_value(DotDict(item_url), DotDict(item), **kwargs)
url = utils.get_abspath(url)
f = urlopen(url)
# TODO: it seems that Yahoo! converts relative links to
# absolute. This needs to be done on the content but seems to
# be a non-trival task python?
content = unicode(f.read(), 'utf-8')
if context and context.verbose:
print '............Content .................'
print content
print '...............EOF...................'
| python | {
"resource": ""
} |
q4325 | extract_dependencies | train | def extract_dependencies(pipe_def=None, pipe_generator=None):
"""Extract modules used by a pipe"""
if pipe_def:
pydeps = gen_dependencies(pipe_def)
| python | {
"resource": ""
} |
q4326 | extract_input | train | def extract_input(pipe_def=None, pipe_generator=None):
"""Extract inputs required by a pipe"""
if pipe_def:
pyinput = gen_input(pipe_def)
| python | {
"resource": ""
} |
q4327 | pythonise | train | def pythonise(id, encoding='ascii'):
"""Return a Python-friendly id"""
replace = {'-': '_', ':': '_', '/': '_'}
func = lambda id, pair: id.replace(pair[0], pair[1])
| python | {
"resource": ""
} |
q4328 | etree_to_dict | train | def etree_to_dict(element):
"""Convert an eTree xml into dict imitating how Yahoo Pipes does it.
todo: further investigate white space and multivalue handling
"""
i = dict(element.items())
content = element.text.strip() if element.text else None
i.update({'content': content}) if content else None
if len(element.getchildren()):
for child in element.iterchildren():
tag = child.tag.split('}', 1)[-1]
new = etree_to_dict(child)
content = _make_content(i, tag, new)
i.update({tag: content}) if content else None
| python | {
"resource": ""
} |
q4329 | broadcast | train | def broadcast(_INPUT, *funcs, **kwargs):
"""copies an iterable and delivers the items to multiple functions
/--> foo2bar(_INPUT) --> \
/ \
_INPUT ---> foo2baz(_INPUT) ---> _OUTPUT
\ /
\--> foo2qux(_INPUT) --> /
One way to construct such a flow in code would be::
| python | {
"resource": ""
} |
q4330 | url_quote | train | def url_quote(url):
"""Ensure url is valid"""
try:
return | python | {
"resource": ""
} |
q4331 | asyncPipeItembuilder | train | def asyncPipeItembuilder(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that asynchronously builds an item. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
conf : {
'attrs': [
{'key': {'value': 'title'}, 'value': {'value': 'new title'}},
{'key': {'value': 'desc.content'}, 'value': {'value': 'new desc'}}
]
}
Returns
------
_OUTPUT : twisted.internet.defer.Deferred generator of items
"""
pkwargs = cdicts(opts, kwargs)
asyncFuncs = | python | {
"resource": ""
} |
q4332 | pipe_itembuilder | train | def pipe_itembuilder(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that builds an item. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items
conf : {
'attrs': [
{'key': {'value': <'title'>}, 'value': {'value': <'chair'>}},
| python | {
"resource": ""
} |
q4333 | asyncPipeLoop | train | def asyncPipeLoop(context=None, _INPUT=None, conf=None, embed=None, **kwargs):
"""An operator that asynchronously loops over the input and performs the
embedded submodule. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
embed : the submodule, i.e., asyncPipe*(context, _INPUT, conf)
Most modules, with the exception of User inputs and Operators can be
sub-modules.
conf : {
'assign_part': {'value': <all or first>},
'assign_to': {'value': <assigned field name>},
'emit_part': {'value': <all or first>},
'mode': {'value': <assign or EMIT>},
'with': {'value': <looped field name | python | {
"resource": ""
} |
q4334 | pipe_loop | train | def pipe_loop(context=None, _INPUT=None, conf=None, embed=None, **kwargs):
"""An operator that loops over the input and performs the embedded
submodule. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
embed : the submodule, i.e., pipe_*(context, _INPUT, conf)
Most modules, with the exception of User inputs and Operators can be
sub-modules.
conf : {
'assign_part': {'value': <all or first>},
'assign_to': {'value': <assigned field name>},
'emit_part': {'value': <all or first>},
'mode': {'value': <assign or EMIT>},
'with': {'value': <looped field name | python | {
"resource": ""
} |
q4335 | pipe_fetchpage | train | def pipe_fetchpage(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches the content of a given web site as a string.
Loopable.
context : pipe2py.Context object
_INPUT : pipeforever asyncPipe or an iterable of items or fields
conf : dict
URL -- url object contain the URL to download
from -- string from where to start the input
to -- string to limit the input
token -- if present, split the input on this token to generate items
Description: http://pipes.yahoo.com/pipes/docs?doc=sources#FetchPage
TODOS:
- don't retrieve pages larger than 200k
- don't retrieve if page is not indexable.
- item delimiter removes the closing tag if using a HTML tag
(not documented but happens)
- items should be cleaned, i.e. stripped of HTML tags
Yields
------
_OUTPUT : items
"""
conf = DotDict(conf)
split_token = conf.get('token', **kwargs)
urls = utils.listize(conf['URL'])
for item in | python | {
"resource": ""
} |
q4336 | pipe_fetchdata | train | def pipe_fetchdata(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches and parses an XML or JSON file. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : {
'URL': {'value': <url>},
'path': {'value': <dot separated path to data list>}
}
Yields
------
_OUTPUT : items
Examples
--------
>>> from os import path as p
>>> from pipe2py.modules.pipeforever import pipe_forever
>>> parent = p.dirname(p.dirname(__file__))
>>> abspath = p.abspath(p.join(parent, 'data', 'gigs.json'))
>>> path = 'value.items'
>>> url = "file://%s" % abspath
>>> conf = {'URL': {'value': url}, 'path': {'value': path}}
>>> pipe_fetchdata(_INPUT=pipe_forever(), conf=conf).next().keys()[:5]
[u'y:repeatcount', u'description', u'pubDate', u'title', u'y:published']
>>> abspath = p.abspath(p.join(parent, 'data', 'places.xml'))
>>> path = 'appointment'
>>> url = "file://%s" % abspath
>>> conf = {'URL': {'value': | python | {
"resource": ""
} |
q4337 | asyncPipeFetch | train | def asyncPipeFetch(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that asynchronously fetches and parses one or more feeds to
return the feed entries. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
conf : {
'URL': [
{'type': 'url', 'value': <url1>},
{'type': 'url', 'value': <url2>},
{'type': 'url', 'value': <url3>},
| python | {
"resource": ""
} |
q4338 | pipe_fetch | train | def pipe_fetch(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches and parses one or more feeds to return the
entries. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : {
'URL': [
{'type': 'url', 'value': <url1>},
{'type': 'url', 'value': <url2>},
{'type': 'url', 'value': <url3>},
| python | {
"resource": ""
} |
q4339 | pipe_filter | train | def pipe_filter(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that filters for source items matching the given rules.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
conf : {
'MODE': {'value': <'permit' or 'block'>},
'COMBINE': {'value': <'and' or 'or'>}
'RULE': [
{
'field': {'value': 'search field'},
'op': {'value': 'one of SWITCH above'},
'value': {'value': 'search term'}
}
]
}
kwargs : other inputs, e.g., to feed terminals for rule values
Returns
-------
_OUTPUT : generator of filtered items
Examples
--------
>>> import os.path as p
>>> from pipe2py.modules.pipeforever import pipe_forever
>>> from pipe2py.modules.pipefetchdata import pipe_fetchdata
>>> parent = p.dirname(p.dirname(__file__))
>>> file_name = p.abspath(p.join(parent, 'data', 'gigs.json'))
>>> path = 'value.items'
>>> url = 'file://%s' % file_name
>>> conf = {'URL': {'value': url}, 'path': {'value': path}}
>>> input = pipe_fetchdata(_INPUT=pipe_forever(), conf=conf)
>>> mode = {'value': 'permit'}
>>> combine = {'value': 'and'}
>>> rule = [{'field': {'value': 'title'}, 'op': {'value': 'contains'}, \
'value': {'value': 'web'}}]
>>> conf = {'MODE': mode, 'COMBINE': combine, 'RULE': rule}
>>> pipe_filter(_INPUT=input, conf=conf).next()['title']
u'E-Commerce Website Developer | Elance Job'
>>> rule = [{'field': {'value': 'title'}, 'op': {'value': 'contains'}, \
'value': {'value': 'kjhlked'}}]
>>> conf = {'MODE': mode, 'COMBINE': combine, 'RULE': rule}
>>> list(pipe_filter(_INPUT=input, conf=conf))
[]
"""
conf = DotDict(conf)
test = kwargs.pop('pass_if', None)
permit | python | {
"resource": ""
} |
q4340 | pipe_split | train | def pipe_split(context, _INPUT, conf, splits, **kwargs):
"""An operator that splits a source into identical copies. Not loopable.
Parameters
----------
context : pipe2py.Context object
| python | {
"resource": ""
} |
q4341 | pipe_datebuilder | train | def pipe_datebuilder(context=None, _INPUT=None, conf=None, **kwargs):
"""A date module that converts a text string into a datetime value. Useful
as terminal data. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items
conf : {'DATE': {'type': 'datetime', 'value': '12/2/2014'}}
Yields
------
_OUTPUT : date timetuples
"""
conf = DotDict(conf)
for item in _INPUT:
_input = DotDict(item)
date = utils.get_value(conf['DATE'], _input, **kwargs).lower()
if date.endswith(' day') or date.endswith(' days'):
count = int(date.split(' ')[0])
new_date = dt.today() + timedelta(days=count)
| python | {
"resource": ""
} |
q4342 | asyncImap | train | def asyncImap(asyncCallable, *iterables):
"""itertools.imap for deferred callables
"""
| python | {
"resource": ""
} |
q4343 | asyncStarCmap | train | def asyncStarCmap(asyncCallable, iterable):
"""itertools.starmap for deferred callables using cooperative multitasking
"""
results = []
| python | {
"resource": ""
} |
q4344 | asyncStarPmap | train | def asyncStarPmap(asyncCallable, iterable):
"""itertools.starmap for deferred callables using parallel cooperative
multitasking
"""
results = [] | python | {
"resource": ""
} |
q4345 | asyncStarMap | train | def asyncStarMap(asyncCallable, iterable):
"""itertools.starmap for deferred callables
"""
| python | {
"resource": ""
} |
q4346 | pipe_rssitembuilder | train | def pipe_rssitembuilder(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that builds an rss item. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever asyncPipe or an iterable of items or fields
conf : {
'mediaContentType': {'type': 'text', 'value': ''},
'mediaContentHeight': {'type': 'text', 'value': ''},
'mediaContentWidth': {'type': 'text', 'value': ''},
'mediaContentURL': {'type': 'text', 'value': 'url'},
'mediaThumbHeight': {'type': 'text', 'value': ''},
'mediaThumbWidth': {'type': 'text', 'value': ''},
'mediaThumbURL': {'type': 'text', 'value': 'url'},
'description': {'type': 'text', 'value': 'description'},
'pubdate': {'type': 'text', | python | {
"resource": ""
} |
q4347 | asyncPipeStrconcat | train | def asyncPipeStrconcat(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously builds a string. Loopable. No direct
input.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
conf : {
'part': [
{'value': <'<img src="'>},
{'subkey': <'img.src'>},
{'value': <'">'>}
]
| python | {
"resource": ""
} |
q4348 | pipe_strconcat | train | def pipe_strconcat(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that builds a string. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items
conf : {
'part': [
{'value': '<img src="'},
{'subkey': 'img.src'},
{'value': '">'}
]
| python | {
"resource": ""
} |
q4349 | asyncPipeUniq | train | def asyncPipeUniq(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that asynchronously filters out non unique items according
to the specified field. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items
conf : {'field': {'type': 'text', 'value': <field to be unique>}}
returns
-------
_OUTPUT : twisted.internet.defer.Deferred generator of unique | python | {
"resource": ""
} |
q4350 | pipe_uniq | train | def pipe_uniq(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that filters out non unique items according to the specified
field. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
kwargs -- other inputs, e.g. to feed terminals for rule values
conf : {'field': {'type': 'text', 'value': <field to be unique>}}
| python | {
"resource": ""
} |
q4351 | asyncPipeUnion | train | def asyncPipeUnion(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that asynchronously merges multiple source together.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
conf : unused
Keyword arguments
-----------------
_OTHER1 : asyncPipe like object
| python | {
"resource": ""
} |
q4352 | pipe_union | train | def pipe_union(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that merges multiple source together. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
conf : unused
Keyword arguments
-----------------
_OTHER1 : pipe2py.modules pipe | python | {
"resource": ""
} |
q4353 | pipe_sort | train | def pipe_sort(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that sorts the input source according to the specified key.
Not loopable. Not lazy.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
kwargs -- other inputs, e.g. to feed terminals for rule values
conf : {
'KEY': [
{
'field': {'type': 'text', 'value': 'title'},
'dir': {'type': 'text', 'value': 'DESC'}
}
]
}
Returns
-------
_OUTPUT : generator of sorted items
"""
| python | {
"resource": ""
} |
q4354 | pipe_createrss | train | def pipe_createrss(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that converts a source into an RSS stream. Not loopable.
"""
conf = DotDict(conf)
for item in _INPUT:
item = DotDict(item)
| python | {
"resource": ""
} |
q4355 | pipe_fetchsitefeed | train | def pipe_fetchsitefeed(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches and parses the first feed found on one or more
sites. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : URL -- url
Yields
------
_OUTPUT : items
"""
conf = DotDict(conf)
urls = utils.listize(conf['URL'])
for item in _INPUT:
for item_url in urls:
url = utils.get_value(DotDict(item_url), DotDict(item), **kwargs)
url = utils.get_abspath(url)
if context and context.verbose:
| python | {
"resource": ""
} |
q4356 | asyncPipeStrreplace | train | def asyncPipeStrreplace(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously replaces text. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items or strings
conf : {
'RULE': [
{
'param': {'value': <match type: 1=first, 2=last, 3=every>},
'find': {'value': <text to find>},
'replace': {'value': <replacement>}
}
]
}
| python | {
"resource": ""
} |
q4357 | pipe_strreplace | train | def pipe_strreplace(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that replaces text. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : iterable of items or strings
conf : {
'RULE': [
{
'param': {'value': <match type: 1=first, 2=last, 3=every>},
'find': {'value': <text to find>},
'replace': {'value': <replacement>}
}
]
} | python | {
"resource": ""
} |
q4358 | asyncPipeUniq | train | def asyncPipeUniq(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that asynchronously returns a specified number of items from
the top of a feed. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items
conf : {
'start': {'type': 'number', value': <starting location>}
| python | {
"resource": ""
} |
q4359 | pipe_truncate | train | def pipe_truncate(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that returns a specified number of items from the top of a
feed. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
kwargs -- terminal, if the truncation value is wired in
conf : {
'start': {'type': 'number', value': <starting location>}
'count': {'type': 'number', value': <desired feed length>}
}
Returns
-------
_OUTPUT : generator of items
"""
funcs = get_splits(None, conf, **cdicts(opts, kwargs))
pieces, _pass | python | {
"resource": ""
} |
q4360 | asyncPipeStringtokenizer | train | def asyncPipeStringtokenizer(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously splits a string into tokens
delimited by separators. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items or strings
conf : {
'to-str': {'value': <delimiter>},
| python | {
"resource": ""
} |
q4361 | asyncPipeExchangerate | train | def asyncPipeExchangerate(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously retrieves the current exchange rate
for a given currency pair. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items or strings (base currency)
conf : {
'quote': {'value': <'USD'>},
'default': {'value': <'USD'>},
| python | {
"resource": ""
} |
q4362 | pipe_exchangerate | train | def pipe_exchangerate(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that retrieves the current exchange rate for a given
currency pair. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : iterable of items or strings (base currency)
conf : {
'quote': {'value': <'USD'>},
'default': {'value': <'USD'>}, | python | {
"resource": ""
} |
q4363 | pipe_strtransform | train | def pipe_strtransform(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that splits a string into tokens delimited by
separators. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : iterable of items or strings
conf : {'transformation': {value': <'swapcase'>}}
Returns
-------
_OUTPUT : generator of | python | {
"resource": ""
} |
q4364 | pipe_privateinput | train | def pipe_privateinput(context=None, _INPUT=None, conf=None, **kwargs):
"""An input that prompts the user for some text and yields it forever.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : unused
conf : {
'name': {'value': 'parameter name'},
'prompt': {'value': | python | {
"resource": ""
} |
q4365 | pipe_dateformat | train | def pipe_dateformat(context=None, _INPUT=None, conf=None, **kwargs):
"""Formats a datetime value. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipedatebuilder pipe like object (iterable of date timetuples)
conf : {
'format': {'value': <'%B %d, %Y'>},
'timezone': {'value': <'EST'>}
}
Yields
------
_OUTPUT : formatted dates
"""
conf = DotDict(conf)
loop_with = kwargs.pop('with', None)
date_format = conf.get('format', **kwargs)
# timezone = conf.get('timezone', **kwargs)
for item in _INPUT:
_with = item.get(loop_with, **kwargs) if loop_with else item
try:
| python | {
"resource": ""
} |
q4366 | pipe_subelement | train | def pipe_subelement(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator extracts select sub-elements from a feed. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
conf : {'path': {'value': <element path>}}
Yields
------
_OUTPUT : items
"""
path = DotDict(conf).get('path', **kwargs)
| python | {
"resource": ""
} |
q4367 | pipe_feedautodiscovery | train | def pipe_feedautodiscovery(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that searches for and returns feed links found in a page.
Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : URL -- url
Yields
------
_OUTPUT : items
"""
conf = DotDict(conf)
urls = utils.listize(conf['URL'])
for item in _INPUT:
for item_url in urls:
url = utils.get_value(DotDict(item_url), DotDict(item), **kwargs)
url = utils.get_abspath(url)
if context and context.verbose:
| python | {
"resource": ""
} |
q4368 | pipe_urlinput | train | def pipe_urlinput(context=None, _INPUT=None, conf=None, **kwargs):
"""An input that prompts the user for a url and yields it forever.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : unused
conf : {
'name': {'value': 'parameter name'},
'prompt': {'value': 'User prompt'},
| python | {
"resource": ""
} |
q4369 | pipe_yql | train | def pipe_yql(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that issues YQL queries. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : yqlquery -- YQL query
# todo: handle envURL
Yields
------
_OUTPUT : query results
"""
# todo: get from a config/env file
url = "http://query.yahooapis.com/v1/public/yql"
conf = DotDict(conf)
query = conf['yqlquery']
for item in _INPUT:
item = DotDict(item)
yql = utils.get_value(query, item, **kwargs) | python | {
"resource": ""
} |
q4370 | pipe_numberinput | train | def pipe_numberinput(context=None, _INPUT=None, conf=None, **kwargs):
"""An input that prompts the user for a number and yields it forever.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : not used
conf : {
'name': {'value': 'parameter name'},
'prompt': {'value': 'User prompt'},
'default': {'value': | python | {
"resource": ""
} |
q4371 | pipe_urlbuilder | train | def pipe_urlbuilder(context=None, _INPUT=None, conf=None, **kwargs):
"""A url module that builds a url. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : {
'PARAM': [
{'key': {'value': <'order'>}, 'value': {'value': <'desc'>}},
{'key': {'value': <'page'>}, 'value': {'value': <'2'>}}
]
'PATH': {'type': 'text', 'value': <''>},
'BASE': {'type': 'text', 'value': <'http://site.com/feed.xml'>},
}
Yields
------
_OUTPUT : url
"""
pkwargs = cdicts(opts, kwargs)
get_params = get_funcs(conf.get('PARAM', []), **kwargs)[0]
get_paths = | python | {
"resource": ""
} |
q4372 | pipe_csv | train | def pipe_csv(context=None, _INPUT=None, conf=None, **kwargs):
"""A source that fetches and parses a csv file to yield items. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipeforever pipe or an iterable of items or fields
conf : URL -- url
skip -- number of header rows to skip
col_mode -- column name source: row=header row(s),
custom=defined in col_name
col_name -- list of custom column names
col_row_start -- first column header row
col_row_end -- last column header row
separator -- column separator
Yields
------
_OUTPUT : items
Note:
Current restrictions:
separator must be 1 character
assumes every row has exactly the expected number of fields, as defined
in the header
"""
conf = DotDict(conf)
conf_sep = conf['separator']
conf_mode = conf['col_mode']
col_name = conf['col_name']
for item in _INPUT:
item = DotDict(item)
url = utils.get_value(conf['URL'], item, **kwargs)
url = utils.get_abspath(url)
separator = utils.get_value(conf_sep, item, encode=True, **kwargs)
skip = int(utils.get_value(conf['skip'], item, **kwargs))
col_mode = utils.get_value(conf_mode, item, **kwargs)
f = urlopen(url)
| python | {
"resource": ""
} |
q4373 | asyncPipeRename | train | def asyncPipeRename(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that asynchronously renames or copies fields in the input
source. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : asyncPipe like object (twisted Deferred iterable of items)
conf : {
'RULE': [
{
'op': {'value': 'rename or copy'},
'field': {'value': 'old field'},
'newval': {'value': 'new field'}
| python | {
"resource": ""
} |
q4374 | pipe_rename | train | def pipe_rename(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that renames or copies fields in the input source.
Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
conf : {
'RULE': [
{
'op': {'value': 'rename or copy'},
'field': {'value': 'old field'},
'newval': {'value': | python | {
"resource": ""
} |
q4375 | pipe_reverse | train | def pipe_reverse(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that reverses the order of source items. Not loopable. Not
lazy.
Parameters
----------
context : pipe2py.Context object
_INPUT | python | {
"resource": ""
} |
q4376 | pipe_count | train | def pipe_count(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that counts the number of _INPUT items and yields it
forever. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
| python | {
"resource": ""
} |
q4377 | asyncPipeSubstr | train | def asyncPipeSubstr(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that asynchronously returns a substring. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : twisted Deferred iterable of items or strings
conf : {
'from': {'type': 'number', value': <starting position>},
'length': {'type': 'number', 'value': <count of characters to return>}
}
returns
-------
| python | {
"resource": ""
} |
q4378 | pipe_substr | train | def pipe_substr(context=None, _INPUT=None, conf=None, **kwargs):
"""A string module that returns a substring. Loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : iterable of items or strings
conf : {
'from': {'type': 'number', value': <starting position>},
'length': {'type': 'number', 'value': <count of characters to return>}
}
Returns
-------
| python | {
"resource": ""
} |
q4379 | serialize_number | train | def serialize_number(x, fmt=SER_BINARY, outlen=None):
""" Serializes `x' to a string of length `outlen' in format `fmt' """
ret = b''
if fmt == SER_BINARY:
while x:
x, r = divmod(x, 256)
ret = six.int2byte(int(r)) + ret
if outlen is not None:
assert len(ret) <= outlen
ret = ret.rjust(outlen, b'\0')
return ret
assert fmt == SER_COMPACT
while x:
| python | {
"resource": ""
} |
q4380 | deserialize_number | train | def deserialize_number(s, fmt=SER_BINARY):
""" Deserializes a number from a string `s' in format `fmt' """
ret = gmpy.mpz(0)
if fmt == SER_BINARY:
if isinstance(s, six.text_type):
raise ValueError(
"Encode `s` to a bytestring yourself to" +
" prevent problems with different default encodings")
for c in s:
ret *= 256
ret += byte2int(c)
| python | {
"resource": ""
} |
q4381 | mod_issquare | train | def mod_issquare(a, p):
""" Returns whether `a' is a square modulo p """
if not a:
return | python | {
"resource": ""
} |
q4382 | mod_root | train | def mod_root(a, p):
""" Return a root of `a' modulo p """
if a == 0:
return 0
if not mod_issquare(a, p):
raise ValueError
n = 2
while mod_issquare(n, p):
n += 1
q = p - 1
r = 0
while not q.getbit(r):
r += 1
q = q >> r
y = pow(n, q, p)
h = q >> 1
b = pow(a, h, p)
x = (a * b) % p
b = (b * x) % p
while b != 1:
h = (b | python | {
"resource": ""
} |
q4383 | encrypt | train | def encrypt(s, pk, pk_format=SER_COMPACT, mac_bytes=10, curve=None):
""" Encrypts `s' for public key `pk' """
curve = (Curve.by_pk_len(len(pk)) if curve is None
| python | {
"resource": ""
} |
q4384 | decrypt | train | def decrypt(s, passphrase, curve='secp160r1', mac_bytes=10):
""" Decrypts `s' with passphrase `passphrase' | python | {
"resource": ""
} |
q4385 | encrypt_file | train | def encrypt_file(in_path_or_file, out_path_or_file, pk, pk_format=SER_COMPACT,
mac_bytes=10, chunk_size=4096, curve=None):
""" Encrypts `in_file' to `out_file' for pubkey `pk' """
close_in, close_out = False, False
in_file, out_file = in_path_or_file, out_path_or_file
try:
if stringlike(in_path_or_file):
in_file = open(in_path_or_file, 'rb')
close_in = True
if stringlike(out_path_or_file):
out_file = open(out_path_or_file, 'wb')
| python | {
"resource": ""
} |
q4386 | decrypt_file | train | def decrypt_file(in_path_or_file, out_path_or_file, passphrase,
curve='secp160r1', mac_bytes=10, chunk_size=4096):
""" Decrypts `in_file' to `out_file' with passphrase `passphrase' """
close_in, close_out = False, False
in_file, out_file = in_path_or_file, out_path_or_file
try:
if stringlike(in_path_or_file):
in_file = open(in_path_or_file, 'rb')
close_in = True
if stringlike(out_path_or_file):
out_file = open(out_path_or_file, 'wb')
| python | {
"resource": ""
} |
q4387 | verify | train | def verify(s, sig, pk, sig_format=SER_COMPACT, pk_format=SER_COMPACT,
curve=None):
""" Verifies that `sig' is a signature of pubkey `pk' for the
message `s'. """
if isinstance(s, six.text_type):
raise ValueError("Encode `s` to a bytestring yourself to" +
" prevent problems | python | {
"resource": ""
} |
q4388 | sign | train | def sign(s, passphrase, sig_format=SER_COMPACT, curve='secp160r1'):
""" Signs `s' with passphrase `passphrase' """
if isinstance(s, six.text_type):
raise ValueError("Encode `s` to a bytestring yourself to" +
" prevent problems with | python | {
"resource": ""
} |
q4389 | PubKey.verify | train | def verify(self, h, sig, sig_fmt=SER_BINARY):
""" Verifies that `sig' is a signature for a message with
SHA-512 hash | python | {
"resource": ""
} |
q4390 | PubKey.encrypt_to | train | def encrypt_to(self, f, mac_bytes=10):
""" Returns a file like object `ef'. Anything written to `ef'
| python | {
"resource": ""
} |
q4391 | PubKey.encrypt | train | def encrypt(self, s, mac_bytes=10):
""" Encrypt `s' for this pubkey. """
if isinstance(s, six.text_type):
raise ValueError(
"Encode `s` to a bytestring yourself to" +
" prevent problems with different default encodings")
| python | {
"resource": ""
} |
q4392 | PrivKey.decrypt_from | train | def decrypt_from(self, f, mac_bytes=10):
""" Decrypts a message from f. """
| python | {
"resource": ""
} |
q4393 | PrivKey.sign | train | def sign(self, h, sig_format=SER_BINARY):
""" Signs the message with SHA-512 hash `h' with this private key. """
outlen = (self.curve.sig_len_compact if sig_format == SER_COMPACT
| python | {
"resource": ""
} |
q4394 | Curve.hash_to_exponent | train | def hash_to_exponent(self, h):
""" Converts a 32 byte hash to an exponent """
ctr = Crypto.Util.Counter.new(128, initial_value=0)
cipher = Crypto.Cipher.AES.new(h,
| python | {
"resource": ""
} |
q4395 | run | train | def run(): # pragma: no cover
"""Defines how to start the CLI for the DomainTools API"""
out_file, out_format, arguments = parse()
user, key = arguments.pop('user', None), arguments.pop('key', None)
if not user or not key:
sys.stderr.write('Credentials are required to perform API calls.\n')
sys.exit(1)
api = API(user, key, https=arguments.pop('https'), verify_ssl=arguments.pop('verify_ssl'),
| python | {
"resource": ""
} |
q4396 | permission_required | train | def permission_required(perm, *lookup_variables, **kwargs):
"""
Decorator for views that checks whether a user has a particular permission
enabled, redirecting to the log-in page if necessary.
"""
login_url = kwargs.pop('login_url', settings.LOGIN_URL)
redirect_field_name = kwargs.pop('redirect_field_name', REDIRECT_FIELD_NAME)
redirect_to_login = kwargs.pop('redirect_to_login', True)
def decorate(view_func):
def decorated(request, *args, **kwargs):
if request.user.is_authenticated():
params = []
for lookup_variable in lookup_variables:
if isinstance(lookup_variable, string_types):
value = kwargs.get(lookup_variable, None)
if value is None:
continue
params.append(value)
elif isinstance(lookup_variable, (tuple, list)):
model, lookup, varname = lookup_variable
value = kwargs.get(varname, None)
if value is None:
continue
if isinstance(model, string_types):
model_class = apps.get_model(*model.split("."))
else:
model_class = model
if model_class is None:
raise ValueError(
"The given argument | python | {
"resource": ""
} |
q4397 | get_permissions | train | def get_permissions(parser, token):
"""
Retrieves all permissions associated with the given obj and user
and assigns the result to a context variable.
Syntax::
{% get_permissions obj %}
{% for perm in permissions %}
{{ perm }}
{% endfor %}
| python | {
"resource": ""
} |
q4398 | get_permission_requests | train | def get_permission_requests(parser, token):
"""
Retrieves all permissions requests associated with the given obj and user
and assigns the result to a context variable.
Syntax::
{% get_permission_requests obj %}
{% for perm in permissions %}
| python | {
"resource": ""
} |
q4399 | get_permission | train | def get_permission(parser, token):
"""
Performs a permission check with the given signature, user and objects
and assigns the result to a context variable.
Syntax::
{% get_permission PERMISSION_LABEL.CHECK_NAME for USER and *OBJS [as VARNAME] %}
{% get_permission "poll_permission.change_poll"
for request.user and poll as "is_allowed" %}
{% get_permission "poll_permission.change_poll"
for request.user and poll,second_poll as "is_allowed" %}
{% if is_allowed %}
I've got ze power to change ze pollllllzzz. Muahahaa.
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.