_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q278900 | last_name | test | def last_name(languages=None):
"""
return a random last name
>>> from mock import patch
>>> with patch('%s._get_lastnames' % __name__, lambda *args: ['aaa']):
... last_name()
'Aaa'
>>> with patch('%s.get_lastnames' % __name__, lambda lang: ['%s_lastname'% lang]):
... last_na... | python | {
"resource": ""
} |
q278901 | Axes.render | test | def render(self):
"""Render the axes data into the dict data"""
for opt,values in self.data.items():
if opt == 'ticks':
self['chxtc'] = '|'.join(values)
else:
self['chx%s'%opt[0]] = '|'.join(values)
return self | python | {
"resource": ""
} |
q278902 | GChart.dataset | test | def dataset(self, data, series=''):
"""
Update the chart's dataset, can be two dimensional or contain string data
"""
self._dataset = data
self._series = series
return self | python | {
"resource": ""
} |
q278903 | GChart.render | test | def render(self):
"""
Renders the chart context and axes into the dict data
"""
self.update(self.axes.render())
encoder = Encoder(self._encoding, None, self._series)
if not 'chs' in self:
self['chs'] = '300x150'
else:
size = self['chs'].spl... | python | {
"resource": ""
} |
q278904 | GChart.check_type | test | def check_type(self, type):
"""Check to see if the type is either in TYPES or fits type name
Returns proper type
"""
if type in TYPES:
return type
tdict = dict(zip(TYPES,TYPES))
tdict.update({
'line': 'lc',
'bar': 'bvs',
'p... | python | {
"resource": ""
} |
q278905 | GChart.url | test | def url(self):
"""
Returns the rendered URL of the chart
"""
self.render()
return self._apiurl + '&'.join(self._parts()).replace(' ','+') | python | {
"resource": ""
} |
q278906 | GChart.show | test | def show(self, *args, **kwargs):
"""
Shows the chart URL in a webbrowser
Other arguments passed to webbrowser.open
"""
from webbrowser import open as webopen
return webopen(str(self), *args, **kwargs) | python | {
"resource": ""
} |
q278907 | GChart.save | test | def save(self, fname=None):
"""
Download the chart from the URL into a filename as a PNG
The filename defaults to the chart title (chtt) if any
"""
if not fname:
fname = self.getname()
assert fname != None, 'You must specify a filename to save to'
if ... | python | {
"resource": ""
} |
q278908 | GChart.urlopen | test | def urlopen(self):
"""
Grabs readable PNG file pointer
"""
req = Request(str(self))
try:
return urlopen(req)
except HTTPError:
_print('The server couldn\'t fulfill the request.')
except URLError:
_print('We failed to reach a ser... | python | {
"resource": ""
} |
q278909 | GChart.image | test | def image(self):
"""
Returns a PngImageFile instance of the chart
You must have PIL installed for this to work
"""
try:
try:
import Image
except ImportError:
from PIL import Image
except ImportError:
rai... | python | {
"resource": ""
} |
q278910 | GChart.write | test | def write(self, fp):
"""
Writes out PNG image data in chunks to file pointer fp
fp must support w or wb
"""
urlfp = self.urlopen().fp
while 1:
try:
fp.write(urlfp.next())
except StopIteration:
return | python | {
"resource": ""
} |
q278911 | GChart.checksum | test | def checksum(self):
"""
Returns the unique SHA1 hexdigest of the chart URL param parts
good for unittesting...
"""
self.render()
return new_sha(''.join(sorted(self._parts()))).hexdigest() | python | {
"resource": ""
} |
q278912 | amount | test | def amount(min=1, max=sys.maxsize, decimal_places=2):
"""
return a random floating number
:param min: minimum value
:param max: maximum value
:param decimal_places: decimal places
:return:
"""
q = '.%s1' % '0' * (decimal_places - 1)
return decimal.Decimal(uniform(min, max)).quan... | python | {
"resource": ""
} |
q278913 | entity_name_decorator | test | def entity_name_decorator(top_cls):
"""
Assign an entity name based on the class immediately inhering from Base.
This is needed because we don't want
entity names to come from any class that simply inherits our classes,
just the ones in our module.
For example, if you create a class Project2 t... | python | {
"resource": ""
} |
q278914 | LessOrEqual.unprotected_and_protected_claims | test | def unprotected_and_protected_claims(self):
"""
This is both verified and self asserted information. As expected
verified information beats self-asserted so if there is both
self-asserted and verified values for a claim then only the verified
will be returned.
"""
... | python | {
"resource": ""
} |
q278915 | Operator.signing_keys_as_jwks | test | def signing_keys_as_jwks(self):
"""
Build a JWKS from the signing keys belonging to the self signer
:return: Dictionary
"""
_l = [x.serialize() for x in self.self_signer.keyjar.get_signing_key()]
if not _l:
_l = [x.serialize() for x in
self.... | python | {
"resource": ""
} |
q278916 | Operator.unpack_metadata_statement | test | def unpack_metadata_statement(self, ms_dict=None, jwt_ms='', keyjar=None,
cls=ClientMetadataStatement, liss=None):
"""
Starting with a signed JWT or a JSON document unpack and verify all
the separate metadata statements.
:param ms_dict: Metadata stateme... | python | {
"resource": ""
} |
q278917 | Operator.pack_metadata_statement | test | def pack_metadata_statement(self, metadata, receiver='', iss='', lifetime=0,
sign_alg=''):
"""
Given a MetadataStatement instance create a signed JWT.
:param metadata: Original metadata statement as a MetadataStatement
instance
:param receiver... | python | {
"resource": ""
} |
q278918 | Operator.evaluate_metadata_statement | test | def evaluate_metadata_statement(self, metadata, keyjar=None):
"""
Computes the resulting metadata statement from a compounded metadata
statement.
If something goes wrong during the evaluation an exception is raised
:param metadata: The compounded metadata statement as a dictiona... | python | {
"resource": ""
} |
q278919 | Operator.correct_usage | test | def correct_usage(self, metadata, federation_usage):
"""
Remove MS paths that are marked to be used for another usage
:param metadata: Metadata statement as dictionary
:param federation_usage: In which context this is expected to used.
:return: Filtered Metadata statement.
... | python | {
"resource": ""
} |
q278920 | Operator.extend_with_ms | test | def extend_with_ms(self, req, sms_dict):
"""
Add signed metadata statements to a request
:param req: The request
:param sms_dict: A dictionary with FO IDs as keys and signed metadata
statements (sms) or uris pointing to sms as values.
:return: The updated request
... | python | {
"resource": ""
} |
q278921 | parse_args | test | def parse_args():
"""
Parses command line args using argparse library
"""
usage = "Usage: create_concordance <infile> [<outfile>]"
description = "Simple Concordance Generator"
argparser = argparse.ArgumentParser(
usage=usage, description=description)
argparser.add_argument(
... | python | {
"resource": ""
} |
q278922 | addCommandLineArgs | test | def addCommandLineArgs(arg_parser):
"""Add logging option to an ArgumentParser."""
arg_parser.register("action", "log_levels", LogLevelAction)
arg_parser.register("action", "log_files", LogFileAction)
arg_parser.register("action", "log_help", LogHelpAction)
group = arg_parser.add_argument_group("Lo... | python | {
"resource": ""
} |
q278923 | applyLoggingOpts | test | def applyLoggingOpts(log_levels, log_files):
"""Apply logging options produced by LogLevelAction and LogFileAction.
More often then not this function is not needed, the actions have already
been taken during the parse, but it can be used in the case they need to be
applied again (e.g. when command line... | python | {
"resource": ""
} |
q278924 | Logger.verbose | test | def verbose(self, msg, *args, **kwargs):
"""Log msg at 'verbose' level, debug < verbose < info"""
self.log(logging.VERBOSE, msg, *args, **kwargs) | python | {
"resource": ""
} |
q278925 | _letter_map | test | def _letter_map(word):
"""Creates a map of letter use in a word.
Args:
word: a string to create a letter map from
Returns:
a dictionary of {letter: integer count of letter in word}
"""
lmap = {}
for letter in word:
try:
lmap[letter] += 1
except KeyE... | python | {
"resource": ""
} |
q278926 | anagrams_in_word | test | def anagrams_in_word(word, sowpods=False, start="", end=""):
"""Finds anagrams in word.
Args:
word: the string to base our search off of
sowpods: boolean to declare TWL or SOWPODS words file
start: a string of starting characters to find anagrams based on
end: a string of ending... | python | {
"resource": ""
} |
q278927 | Error.asAMP | test | def asAMP(cls):
"""
Returns the exception's name in an AMP Command friendly format.
For example, given a class named ``ExampleExceptionClass``, returns
``"EXAMPLE_EXCEPTION_CLASS"``.
"""
parts = groupByUpperCase(cls.__name__)
return cls, "_".join(part.upper() for... | python | {
"resource": ""
} |
q278928 | transform_timeseries_data | test | def transform_timeseries_data(timeseries, start, end=None):
"""Transforms a Go Metrics API metric result into a list of
values for a given window period.
start and end are expected to be Unix timestamps in microseconds.
"""
data = []
include = False
for metric, points in timeseries.items():... | python | {
"resource": ""
} |
q278929 | get_last_value_from_timeseries | test | def get_last_value_from_timeseries(timeseries):
"""Gets the most recent non-zero value for a .last metric or zero
for empty data."""
if not timeseries:
return 0
for metric, points in timeseries.items():
return next((p['y'] for p in reversed(points) if p['y'] > 0), 0) | python | {
"resource": ""
} |
q278930 | validate_page_number | test | def validate_page_number(number):
"""Validate the given 1-based page number."""
try:
number = int(number)
except (TypeError, ValueError):
raise PageNotAnInteger('That page number is not an integer')
if number < 1:
raise EmptyPage('That page number is less than 1')
return numb... | python | {
"resource": ""
} |
q278931 | get_page_of_iterator | test | def get_page_of_iterator(iterator, page_size, page_number):
"""
Get a page from an interator, handling invalid input from the page number
by defaulting to the first page.
"""
try:
page_number = validate_page_number(page_number)
except (PageNotAnInteger, EmptyPage):
page_number = ... | python | {
"resource": ""
} |
q278932 | chmod | test | def chmod(path, mode, recursive=True):
""" alternative to os.
"""
if recursive:
cmd = 'chmod -R %s %s' % (mode, path)
else:
cmd = 'chmod %s %s' % (mode, path)
return sh(cmd) | python | {
"resource": ""
} |
q278933 | make_internal_signing_service | test | def make_internal_signing_service(config, entity_id):
"""
Given configuration initiate an InternalSigningService instance
:param config: The signing service configuration
:param entity_id: The entity identifier
:return: A InternalSigningService instance
"""
_args = dict([(k, v) for k, v in... | python | {
"resource": ""
} |
q278934 | make_signing_service | test | def make_signing_service(config, entity_id):
"""
Given configuration initiate a SigningService instance
:param config: The signing service configuration
:param entity_id: The entity identifier
:return: A SigningService instance
"""
_args = dict([(k, v) for k, v in config.items() if k in KJ... | python | {
"resource": ""
} |
q278935 | InternalSigningService.sign | test | def sign(self, req, receiver='', iss='', lifetime=0, sign_alg='', aud=None):
"""
Creates a signed JWT
:param req: Original metadata statement as a
:py:class:`MetadataStatement` instance
:param receiver: The intended audience for the JWS
:param iss: Issuer or the JWT
... | python | {
"resource": ""
} |
q278936 | WebSigningServiceClient.create | test | def create(self, req, **kwargs):
"""
Uses POST to send a first metadata statement signing request to
a signing service.
:param req: The metadata statement that the entity wants signed
:return: returns a dictionary with 'sms' and 'loc' as keys.
"""
response = req... | python | {
"resource": ""
} |
q278937 | WebSigningServiceClient.update_metadata_statement | test | def update_metadata_statement(self, location, req):
"""
Uses PUT to update an earlier accepted and signed metadata statement.
:param location: A URL to which the update request is sent
:param req: The diff between what is registereed with the signing
service and what it shou... | python | {
"resource": ""
} |
q278938 | WebSigningServiceClient.update_signature | test | def update_signature(self, location):
"""
Uses GET to get a newly signed metadata statement.
:param location: A URL to which the request is sent
:return: returns a dictionary with 'sms' and 'loc' as keys.
"""
response = requests.get(location, **self.req_args())
r... | python | {
"resource": ""
} |
q278939 | Package._yield_bundle_contents | test | def _yield_bundle_contents(self, data):
"""Yield bundle contents from the given dict.
Each item yielded will be either a string representing a file path
or a bundle."""
if isinstance(data, list):
contents = data
else:
contents = data.get('contents', [])
... | python | {
"resource": ""
} |
q278940 | Package._create_bundle | test | def _create_bundle(self, data):
"""Return a bundle initialised by the given dict."""
kwargs = {}
filters = None
if isinstance(data, dict):
kwargs.update(
filters=data.get('filters', None),
output=data.get('output', None),
debug=... | python | {
"resource": ""
} |
q278941 | Package.urls_for | test | def urls_for(self, asset_type, *args, **kwargs):
"""Returns urls needed to include all assets of asset_type
"""
return self.urls_for_depends(asset_type, *args, **kwargs) + \
self.urls_for_self(asset_type, *args, **kwargs) | python | {
"resource": ""
} |
q278942 | Package.html_tags_for | test | def html_tags_for(self, asset_type, *args, **kwargs):
"""Return html tags for urls of asset_type
"""
html = []
for ref in self.depends:
html.append(self._ref(ref).html_tags_for(asset_type, *args, **kwargs))
if asset_type in self.typed_bundles:
html.append(... | python | {
"resource": ""
} |
q278943 | Package.html_tags | test | def html_tags(self, *args, **kwargs):
"""Return all html tags for all asset_type
"""
html = []
for asset_type in list_asset_types():
html.append(self.html_tags_for(asset_type.name, *args, **kwargs))
return "\n".join(html) | python | {
"resource": ""
} |
q278944 | protocolise | test | def protocolise(url):
"""
Given a URL, check to see if there is an assocaited protocol.
If not, set the protocol to HTTP and return the protocolised URL
"""
# Use the regex to match http//localhost/something
protore = re.compile(r'https?:{0,1}/{1,2}')
parsed = urlparse.urlparse(url)
if ... | python | {
"resource": ""
} |
q278945 | find_links | test | def find_links(url):
"""
Find the href destinations of all links at URL
Arguments:
- `url`:
Return: list[str]
Exceptions: None
"""
url = protocolise(url)
content = requests.get(url).content
flike = StringIO(content)
root = html.parse(flike).getroot()
atags = root.cssse... | python | {
"resource": ""
} |
q278946 | _connected | test | def _connected(client):
"""
Connected to AMP server, start listening locally, and give the AMP
client a reference to the local listening factory.
"""
log.msg("Connected to AMP server, starting to listen locally...")
localFactory = multiplexing.ProxyingFactory(client, "hello")
return listenin... | python | {
"resource": ""
} |
q278947 | ServiceModules.get_modules | test | def get_modules(self):
"""Get modules by project_abspath and packages_scan.
Traverse all files under folder packages_scan which set by customer.
And get all modules name.
"""
if not self.project_abspath:
raise TypeError("project_abspath can not be empty.")
pa... | python | {
"resource": ""
} |
q278948 | ServiceModules.import_modules | test | def import_modules(self):
"""Import customer's service module."""
modules = self.get_modules()
log.info("import service modules: " + str(modules))
try:
for module in modules:
__import__(module)
except ImportError as error:
raise ImportModul... | python | {
"resource": ""
} |
q278949 | to_dates | test | def to_dates(param):
"""
This function takes a date string in various formats
and converts it to a normalized and validated date range. A list
with two elements is returned, lower and upper date boundary.
Valid inputs are, for example:
2012 => Jan 1 20012 - Dec 31 2012 (whole year)... | python | {
"resource": ""
} |
q278950 | Doc_Formatter.select_fields | test | def select_fields(doc, field_list):
'''
Take 'doc' and create a new doc using only keys from the 'fields' list.
Supports referencing fields using dotted notation "a.b.c" so we can parse
nested fields the way MongoDB does. The nested field class is a hack. It should
be a sub-class... | python | {
"resource": ""
} |
q278951 | Doc_Formatter.date_map | test | def date_map(doc, datemap_list, time_format=None):
'''
For all the datetime fields in "datemap" find that key in doc and map the datetime object to
a strftime string. This pprint and others will print out readable datetimes.
'''
if datemap_list:
for i in datemap_list:... | python | {
"resource": ""
} |
q278952 | CursorFormatter.printCursor | test | def printCursor(self, fieldnames=None, datemap=None, time_format=None):
'''
Output a cursor to a filename or stdout if filename is "-".
fmt defines whether we output CSV or JSON.
'''
if self._format == 'csv':
count = self.printCSVCursor(fieldnames, datemap, time_form... | python | {
"resource": ""
} |
q278953 | CursorFormatter.output | test | def output(self, fieldNames=None, datemap=None, time_format=None):
'''
Output all fields using the fieldNames list. for fields in the list datemap indicates the field must
be date
'''
count = self.printCursor(self._cursor, fieldNames, datemap, time_format) | python | {
"resource": ""
} |
q278954 | get_tasks | test | def get_tasks(do_tasks, dep_graph):
"""Given a list of tasks to perform and a dependency graph, return the tasks
that must be performed, in the correct order"""
#XXX: Is it important that if a task has "foo" before "bar" as a dep,
# that foo executes before bar? Why? ATM this may not happen.
#... | python | {
"resource": ""
} |
q278955 | add_default_deps | test | def add_default_deps(project):
"""Add or create the default departments for the given project
:param project: the project that needs default departments
:type project: :class:`muke.models.Project`
:returns: None
:rtype: None
:raises: None
"""
# create deps for project
for name, shor... | python | {
"resource": ""
} |
q278956 | add_default_atypes | test | def add_default_atypes(project):
"""Add or create the default assettypes for the given project
:param project: the project that needs default assettypes
:type project: :class:`muke.models.Project`
:returns: None
:rtype: None
:raises: None
"""
# create assettypes for project
for name... | python | {
"resource": ""
} |
q278957 | add_default_sequences | test | def add_default_sequences(project):
"""Add or create the default sequences for the given project
:param project: the project that needs default sequences
:type project: :class:`muke.models.Project`
:returns: None
:rtype: None
:raises: None
"""
# create sequences for project
seqs = [... | python | {
"resource": ""
} |
q278958 | add_userrnd_shot | test | def add_userrnd_shot(project):
"""Add a rnd shot for every user in the project
:param project: the project that needs its rnd shots updated
:type project: :class:`muke.models.Project`
:returns: None
:rtype: None
:raises: None
"""
rndseq = project.sequence_set.get(name=RNDSEQ_NAME)
u... | python | {
"resource": ""
} |
q278959 | prj_post_save_handler | test | def prj_post_save_handler(sender, **kwargs):
""" Post save receiver for when a Project is saved.
Creates a rnd shot for every user.
On creations does:
1. create all default departments
2. create all default assettypes
3. create all default sequences
:param sender: the project cl... | python | {
"resource": ""
} |
q278960 | seq_post_save_handler | test | def seq_post_save_handler(sender, **kwargs):
""" Post save receiver for when a sequence is saved.
creates a global shot.
:param sender: the sequence class
:type sender: :class:`muke.models.Sequence`
:returns: None
:raises: None
"""
if not kwargs['created']:
return
seq = k... | python | {
"resource": ""
} |
q278961 | create_all_tasks | test | def create_all_tasks(element):
"""Create all tasks for the element
:param element: The shot or asset that needs tasks
:type element: :class:`muke.models.Shot` | :class:`muke.models.Asset`
:returns: None
:rtype: None
:raises: None
"""
prj = element.project
if isinstance(element, Asse... | python | {
"resource": ""
} |
q278962 | ConnectionPool.pre_connect | test | def pre_connect(self, peer):
"""
Ensures that we have an open connection to the given peer.
Returns the peer id. This should be equal to the given one, but
it might not if the given peer was, say, the IP and the peer
actually identifies itself with a host name. The retur... | python | {
"resource": ""
} |
q278963 | ConnectionPool.send | test | def send(self, peer, typename, data):
"""
Sends a packet to a peer.
"""
def attempt_to_send(_):
if peer not in self._connections:
d = self._connect(peer)
d.addCallback(attempt_to_send)
return d
else:
... | python | {
"resource": ""
} |
q278964 | Config.get_config_value | test | def get_config_value(self, section, key, return_type: type):
"""Read customer's config value by section and key.
:param section: config file's section. i.e [default]
:param key: config file's key under section. i.e packages_scan
:param return_type: return value type, str | int | bool.
... | python | {
"resource": ""
} |
q278965 | nova | test | def nova(*arg):
"""
Nova annotation for adding function to process nova notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_event_type(O... | python | {
"resource": ""
} |
q278966 | cinder | test | def cinder(*arg):
"""
Cinder annotation for adding function to process cinder notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_event_... | python | {
"resource": ""
} |
q278967 | neutron | test | def neutron(*arg):
"""
Neutron annotation for adding function to process neutron notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_eve... | python | {
"resource": ""
} |
q278968 | glance | test | def glance(*arg):
"""
Glance annotation for adding function to process glance notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_event_... | python | {
"resource": ""
} |
q278969 | swift | test | def swift(*arg):
"""
Swift annotation for adding function to process swift notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_event_typ... | python | {
"resource": ""
} |
q278970 | keystone | test | def keystone(*arg):
"""
Swift annotation for adding function to process keystone notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_eve... | python | {
"resource": ""
} |
q278971 | heat | test | def heat(*arg):
"""
Heat annotation for adding function to process heat notification.
if event_type include wildcard, will put {pattern: function} into process_wildcard dict
else will put {event_type: function} into process dict
:param arg: event_type of notification
"""
check_event_type(O... | python | {
"resource": ""
} |
q278972 | MultiplexingCommandLocator.addFactory | test | def addFactory(self, identifier, factory):
"""Adds a factory.
After calling this method, remote clients will be able to
connect to it.
This will call ``factory.doStart``.
"""
factory.doStart()
self._factories[identifier] = factory | python | {
"resource": ""
} |
q278973 | MultiplexingCommandLocator.removeFactory | test | def removeFactory(self, identifier):
"""Removes a factory.
After calling this method, remote clients will no longer be
able to connect to it.
This will call the factory's ``doStop`` method.
"""
factory = self._factories.pop(identifier)
factory.doStop()
... | python | {
"resource": ""
} |
q278974 | MultiplexingCommandLocator.connect | test | def connect(self, factory):
"""Attempts to connect using a given factory.
This will find the requested factory and use it to build a
protocol as if the AMP protocol's peer was making the
connection. It will create a transport for the protocol and
connect it immediately. It will ... | python | {
"resource": ""
} |
q278975 | MultiplexingCommandLocator.receiveData | test | def receiveData(self, connection, data):
"""
Receives some data for the given protocol.
"""
try:
protocol = self._protocols[connection]
except KeyError:
raise NoSuchConnection()
protocol.dataReceived(data)
return {} | python | {
"resource": ""
} |
q278976 | MultiplexingCommandLocator.disconnect | test | def disconnect(self, connection):
"""
Disconnects the given protocol.
"""
proto = self._protocols.pop(connection)
proto.transport = None
return {} | python | {
"resource": ""
} |
q278977 | ProxyingProtocol._callRemote | test | def _callRemote(self, command, **kwargs):
"""Shorthand for ``callRemote``.
This uses the factory's connection to the AMP peer.
"""
return self.factory.remote.callRemote(command, **kwargs) | python | {
"resource": ""
} |
q278978 | ProxyingProtocol.connectionMade | test | def connectionMade(self):
"""Create a multiplexed stream connection.
Connect to the AMP server's multiplexed factory using the
identifier (defined by this class' factory). When done, stores
the connection reference and causes buffered data to be sent.
"""
log.msg("Creat... | python | {
"resource": ""
} |
q278979 | ProxyingProtocol._multiplexedConnectionMade | test | def _multiplexedConnectionMade(self, response):
"""Stores a reference to the connection, registers this protocol on
the factory as one related to a multiplexed AMP connection,
and sends currently buffered data. Gets rid of the buffer
afterwards.
"""
self.connection = con... | python | {
"resource": ""
} |
q278980 | ProxyingProtocol.dataReceived | test | def dataReceived(self, data):
"""Received some data from the local side.
If we have set up the multiplexed connection, sends the data
over the multiplexed connection. Otherwise, buffers.
"""
log.msg("{} bytes of data received locally".format(len(data)))
if self.connecti... | python | {
"resource": ""
} |
q278981 | ProxyingProtocol._sendData | test | def _sendData(self, data):
"""Actually sends data over the wire.
"""
d = self._callRemote(Transmit, connection=self.connection, data=data)
d.addErrback(log.err) | python | {
"resource": ""
} |
q278982 | ProxyingProtocol.connectionLost | test | def connectionLost(self, reason):
"""If we already have an AMP connection registered on the factory,
get rid of it.
"""
if self.connection is not None:
del self.factory.protocols[self.connection] | python | {
"resource": ""
} |
q278983 | ProxyingAMPLocator.getLocalProtocol | test | def getLocalProtocol(self, connectionIdentifier):
"""Attempts to get a local protocol by connection identifier.
"""
for factory in self.localFactories:
try:
return factory.protocols[connectionIdentifier]
except KeyError:
continue
... | python | {
"resource": ""
} |
q278984 | ProxyingAMPLocator.remoteDataReceived | test | def remoteDataReceived(self, connection, data):
"""Some data was received from the remote end. Find the matching
protocol and replay it.
"""
proto = self.getLocalProtocol(connection)
proto.transport.write(data)
return {} | python | {
"resource": ""
} |
q278985 | ProxyingAMPLocator.disconnect | test | def disconnect(self, connection):
"""The other side has asked us to disconnect.
"""
proto = self.getLocalProtocol(connection)
proto.transport.loseConnection()
return {} | python | {
"resource": ""
} |
q278986 | centered | test | def centered(mystring, linewidth=None, fill=" "):
'''Takes a string, centres it, and pads it on both sides'''
if linewidth is None:
linewidth = get_terminal_size().columns - 1
sides = (linewidth - length_no_ansi(mystring))//2
extra = (linewidth - length_no_ansi(mystring)) % 2
fill = fill[:1]... | python | {
"resource": ""
} |
q278987 | clock_on_right | test | def clock_on_right(mystring):
'''Takes a string, and prints it with the time right aligned'''
taken = length_no_ansi(mystring)
padding = (get_terminal_size().columns - 1) - taken - 5
clock = time.strftime("%I:%M", time.localtime())
print(mystring + " "*padding + clock) | python | {
"resource": ""
} |
q278988 | version_number_str | test | def version_number_str(major, minor=0, patch=0, prerelease=None, build=None):
"""
Takes the parts of a semantic version number, and returns a nicely
formatted string.
"""
version = str(major) + '.' + str(minor) + '.' + str(patch)
if prerelease:
if prerelease.startswith('-'):
... | python | {
"resource": ""
} |
q278989 | identify_unit_framework | test | def identify_unit_framework(target_unit):
"""
Identify whether the user is requesting unit validation against
astropy.units, pint, or quantities.
"""
if HAS_ASTROPY:
from astropy.units import UnitBase
if isinstance(target_unit, UnitBase):
return ASTROPY
if HAS_PI... | python | {
"resource": ""
} |
q278990 | assert_unit_convertability | test | def assert_unit_convertability(name, value, target_unit, unit_framework):
"""
Check that a value has physical type consistent with user-specified units
Note that this does not convert the value, only check that the units have
the right physical dimensionality.
Parameters
----------
name : ... | python | {
"resource": ""
} |
q278991 | pad | test | def pad(data_to_pad, block_size, style='pkcs7'):
"""Apply standard padding.
:Parameters:
data_to_pad : byte string
The data that needs to be padded.
block_size : integer
The block boundary to use for padding. The output length is guaranteed
to be a multiple of ``block_size``... | python | {
"resource": ""
} |
q278992 | unpad | test | def unpad(padded_data, block_size, style='pkcs7'):
"""Remove standard padding.
:Parameters:
padded_data : byte string
A piece of data with padding that needs to be stripped.
block_size : integer
The block boundary to use for padding. The input length
must be a multiple of ``... | python | {
"resource": ""
} |
q278993 | FederationEntity.self_sign | test | def self_sign(self, req, receiver='', aud=None):
"""
Sign the extended request.
:param req: Request, a :py:class:`fedoidcmsg.MetadataStatement' instance
:param receiver: The intended user of this metadata statement
:param aud: The audience, a list of receivers.
:return: ... | python | {
"resource": ""
} |
q278994 | FederationEntityOOB.gather_metadata_statements | test | def gather_metadata_statements(self, fos=None, context=''):
"""
Only gathers metadata statements and returns them.
:param fos: Signed metadata statements from these Federation Operators
should be added.
:param context: context of the metadata exchange
:return: Dictio... | python | {
"resource": ""
} |
q278995 | pretty_print | test | def pretty_print(input_word, anagrams, by_length=False):
"""Prints the anagram results sorted by score to stdout.
Args:
input_word: the base word we searched on
anagrams: generator of (word, score) from anagrams_in_word
by_length: a boolean to declare printing by length instead of score... | python | {
"resource": ""
} |
q278996 | argument_parser | test | def argument_parser(args):
"""Argparse logic, command line options.
Args:
args: sys.argv[1:], everything passed to the program after its name
Returns:
A tuple of:
a list of words/letters to search
a boolean to declare if we want to use the sowpods words file
... | python | {
"resource": ""
} |
q278997 | main | test | def main(arguments=None):
"""Main command line entry point."""
if not arguments:
arguments = sys.argv[1:]
wordlist, sowpods, by_length, start, end = argument_parser(arguments)
for word in wordlist:
pretty_print(
word,
anagrams_in_word(word, sowpods, start, end),... | python | {
"resource": ""
} |
q278998 | PacketProtocol.dataReceived | test | def dataReceived(self, data):
"""
Do not overwrite this method. Instead implement `on_...` methods for the
registered typenames to handle incomming packets.
"""
self._unprocessed_data.enqueue(data)
while True:
if len(self._unprocesse... | python | {
"resource": ""
} |
q278999 | PacketProtocol.on_unregistered_type | test | def on_unregistered_type(self, typekey, packet):
"""
Invoked if a packet with an unregistered type was received.
Default behaviour is to log and close the connection.
"""
log.msg("Missing handler for typekey %s in %s. Closing connection." % (typekey, type(self).__name__)... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.