_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q276100
always_iterable
test
def always_iterable(item): """ Given an object, always return an iterable. If the item is not already iterable, return a tuple containing only the item. If item is None, an empty iterable is returned. >>> always_iterable([1,2,3]) <list_iterator...> >>> always_iterable('foo') <tuple_iterator...> >>> always_ite...
python
{ "resource": "" }
q276101
suppress_exceptions
test
def suppress_exceptions(callables, *exceptions): """ Call each callable in callables, suppressing any exceptions supplied. If no exception classes are supplied, all Exceptions will be suppressed. >>> import functools >>> c1 = functools.partial(int, 'a') >>> c2 = functools.partial(int, '10') >>> list(suppress_ex...
python
{ "resource": "" }
q276102
duplicates
test
def duplicates(*iterables, **kwargs): """ Yield duplicate items from any number of sorted iterables of items >>> items_a = [1, 2, 3] >>> items_b = [0, 3, 4, 5, 6] >>> list(duplicates(items_a, items_b)) [(3, 3)] It won't behave as you expect if the iterables aren't ordered >>> items_b.append(1) >>> list(dupl...
python
{ "resource": "" }
q276103
assert_ordered
test
def assert_ordered(iterable, key=lambda x: x, comp=operator.le): """ Assert that for all items in the iterable, they're in order based on comp >>> list(assert_ordered(range(5))) [0, 1, 2, 3, 4] >>> list(assert_ordered(range(5), comp=operator.ge)) Traceback (most recent call last): ... AssertionError: 0 < 1 >>...
python
{ "resource": "" }
q276104
_swap_on_miss
test
def _swap_on_miss(partition_result): """ Given a partition_dict result, if the partition missed, swap the before and after. """ before, item, after = partition_result return (before, item, after) if item else (after, item, before)
python
{ "resource": "" }
q276105
partition_dict
test
def partition_dict(items, key): """ Given an ordered dictionary of items and a key in that dict, return an ordered dict of items before, the keyed item, and an ordered dict of items after. >>> od = collections.OrderedDict(zip(range(5), 'abcde')) >>> before, item, after = partition_dict(od, 3) >>> before Ordere...
python
{ "resource": "" }
q276106
GroupbySaved.get_first_n_queues
test
def get_first_n_queues(self, n): """ Run through the sequence until n queues are created and return them. If fewer are created, return those plus empty iterables to compensate. """ try: while len(self.queues) < n: self.__fetch__() except StopIteration: pass values = list(self.queues.values()) ...
python
{ "resource": "" }
q276107
Reusable.reset
test
def reset(self): """ Resets the iterator to the start. Any remaining values in the current iteration are discarded. """ self.__iterator, self.__saved = itertools.tee(self.__saved)
python
{ "resource": "" }
q276108
parse_as_var
test
def parse_as_var(parser, token): """ Parse the remainder of the token, to find a "as varname" statement. :param parser: The "parser" object that ``@register.tag`` provides. :type parser: :class:`~django.template.Parser` :param token: The "token" object that ``@register.tag`` provides. :type tok...
python
{ "resource": "" }
q276109
template_tag
test
def template_tag(library, name): """ Decorator to register class tags :param library: The template tag library, typically instantiated as ``register = Library()``. :type library: :class:`~django.template.Library` :param name: The name of the template tag :type name: str Example: .. co...
python
{ "resource": "" }
q276110
PublicKeychain.descendant
test
def descendant(self, chain_path): """ A descendant is a child many steps down. """ public_child = self.hdkeychain chain_step_bytes = 4 max_bits_per_step = 2**31 chain_steps = [ int(chain_path[i:i+chain_step_bytes*2], 16) % max_bits_per_step for i i...
python
{ "resource": "" }
q276111
SQLiteSchemaExtractor.fetch_sqlite_master
test
def fetch_sqlite_master(self): """ Get sqlite_master table information as a list of dictionaries. :return: sqlite_master table information. :rtype: list :Sample Code: .. code:: python from sqliteschema import SQLiteSchemaExtractor p...
python
{ "resource": "" }
q276112
object_iter
test
def object_iter(obj, parent=None, parent_key=None, idx=None, siblings=None): """Yields each node of object graph in postorder.""" obj_node = Node(value=obj, parent=parent, parent_key=parent_key, siblings=siblings, idx=idx) if isinstance(obj, list): _siblings = len(o...
python
{ "resource": "" }
q276113
select
test
def select(selector, obj): """Appy selector to obj and return matching nodes. If only one node is found, return it, otherwise return a list of matches. Returns False on syntax error. None if no results found. """ parser = Parser(obj) try: return parser.parse(selector) except Select...
python
{ "resource": "" }
q276114
Parser.parse
test
def parse(self, selector): """Accept a list of tokens. Returns matched nodes of self.obj.""" log.debug(self.obj) tokens = lex(selector) if self.peek(tokens, 'operator') == '*': self.match(tokens, 'operator') results = list(object_iter(self.obj)) else: ...
python
{ "resource": "" }
q276115
Parser.selector_production
test
def selector_production(self, tokens): """Production for a full selector.""" validators = [] # the following productions should return predicate functions. if self.peek(tokens, 'type'): type_ = self.match(tokens, 'type') validators.append(self.type_production(ty...
python
{ "resource": "" }
q276116
Parser.parents
test
def parents(self, lhs, rhs): """Find nodes in rhs which have parents in lhs.""" return [node for node in rhs if node.parent in lhs]
python
{ "resource": "" }
q276117
Parser.ancestors
test
def ancestors(self, lhs, rhs): """Return nodes from rhs which have ancestors in lhs.""" def _search(node): if node in lhs: return True if not node.parent: return False return _search(node.parent) return [node for node in rhs i...
python
{ "resource": "" }
q276118
Parser.siblings
test
def siblings(self, lhs, rhs): """Find nodes in rhs having common parents in lhs.""" parents = [node.parent for node in lhs] return [node for node in rhs if node.parent in parents]
python
{ "resource": "" }
q276119
Parser.nth_child_production
test
def nth_child_production(self, lexeme, tokens): """Parse args and pass them to pclass_func_validator.""" args = self.match(tokens, 'expr') pat = self.nth_child_pat.match(args) if pat.group(5): a = 2 b = 1 if pat.group(5) == 'odd' else 0 elif pat.group(6...
python
{ "resource": "" }
q276120
Parser._match_nodes
test
def _match_nodes(self, validators, obj): """Apply each validator in validators to each node in obj. Return each node in obj which matches all validators. """ results = [] for node in object_iter(obj): if all([validate(node) for validate in validators]): ...
python
{ "resource": "" }
q276121
ping
test
def ping(dst, count, inter=0.2, maxwait=1000, size=64): """Sends ICMP echo requests to destination `dst` `count` times. Returns a deferred which fires when responses are finished. """ def _then(result, p): p.stopListening() return result d = defer.Deferred() p = ICMPPort(0, ICMP...
python
{ "resource": "" }
q276122
HTTPRequest.getBody
test
def getBody(self, url, method='GET', headers={}, data=None, socket=None): """Make an HTTP request and return the body """ if not 'User-Agent' in headers: headers['User-Agent'] = ['Tensor HTTP checker'] return self.request(url, method, headers, data, socket)
python
{ "resource": "" }
q276123
PersistentCache.expire
test
def expire(self, age): """Expire any items in the cache older than `age` seconds""" now = time.time() cache = self._acquire_cache() expired = [k for k, v in cache.items() if (now - v[0]) > age] for k in expired: if k in cache: del cache[k] ...
python
{ "resource": "" }
q276124
PersistentCache.set
test
def set(self, k, v): """Set a key `k` to value `v`""" self.store[k] = (time.time(), v) self._persist()
python
{ "resource": "" }
q276125
PersistentCache.get
test
def get(self, k): """Returns key contents, and modify time""" if self._changed(): self._read() if k in self.store: return tuple(self.store[k]) else: return None
python
{ "resource": "" }
q276126
PersistentCache.contains
test
def contains(self, k): """Return True if key `k` exists""" if self._changed(): self._read() return k in self.store.keys()
python
{ "resource": "" }
q276127
NistBeacon.chain_check
test
def chain_check(cls, timestamp: int) -> bool: """ Given a record timestamp, verify the chain integrity. :param timestamp: UNIX time / POSIX time / Epoch time :return: 'True' if the timestamp fits the chain. 'False' otherwise. """ # Creation is messy. # You want ...
python
{ "resource": "" }
q276128
NistBeaconValue.from_json
test
def from_json(cls, input_json: str) -> 'NistBeaconValue': """ Convert a string of JSON which represents a NIST randomness beacon value into a 'NistBeaconValue' object. :param input_json: JSON to build a 'Nist RandomnessBeaconValue' from :return: A 'NistBeaconValue' object, 'None...
python
{ "resource": "" }
q276129
NistBeaconValue.from_xml
test
def from_xml(cls, input_xml: str) -> 'NistBeaconValue': """ Convert a string of XML which represents a NIST Randomness Beacon value into a 'NistBeaconValue' object. :param input_xml: XML to build a 'NistBeaconValue' from :return: A 'NistBeaconValue' object, 'None' otherwise ...
python
{ "resource": "" }
q276130
MinifiedJsTemplateResponse.rendered_content
test
def rendered_content(self): """Returns a 'minified' version of the javascript content""" template = self.resolve_template(self.template_name) if django.VERSION[1] < 8: if template.name.endswith('.min'): return super(MinifiedJsTemplateResponse, self).rendered_content ...
python
{ "resource": "" }
q276131
LogFollower.get_fn
test
def get_fn(self, fn, max_lines=None): """Passes each parsed log line to `fn` This is a better idea than storing a giant log file in memory """ stat = os.stat(self.logfile) if (stat.st_ino == self.lastInode) and (stat.st_size == self.lastSize): # Nothing new ...
python
{ "resource": "" }
q276132
LogFollower.get
test
def get(self, max_lines=None): """Returns a big list of all log lines since the last run """ rows = [] self.get_fn(lambda row: rows.append(row), max_lines=max_lines) return rows
python
{ "resource": "" }
q276133
TokenMixin.validate_token
test
def validate_token(self, token, expected_data=None): """Validate secret link token. :param token: Token value. :param expected_data: A dictionary of key/values that must be present in the data part of the token (i.e. included via ``extra_data`` in ``create_token``). ...
python
{ "resource": "" }
q276134
EncryptedTokenMixIn.engine
test
def engine(self): """Get cryptographic engine.""" if not hasattr(self, '_engine'): from cryptography.fernet import Fernet from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes digest = hashes.Hash(hashe...
python
{ "resource": "" }
q276135
EmailConfirmationSerializer.compat_validate_token
test
def compat_validate_token(cls, *args, **kwargs): """Multiple algorithm-compatible token validation.""" data = None for algorithm in SUPPORTED_DIGEST_ALGORITHMS: data = cls(algorithm_name=algorithm).validate_token( *args, **kwargs) if not data: # move to n...
python
{ "resource": "" }
q276136
SecretLinkFactory.create_token
test
def create_token(cls, obj_id, data, expires_at=None): """Create the secret link token.""" if expires_at: s = TimedSecretLinkSerializer(expires_at=expires_at) else: s = SecretLinkSerializer() return s.create_token(obj_id, data)
python
{ "resource": "" }
q276137
Counter32
test
def Counter32(a, b, delta): """32bit counter aggregator with wrapping """ if b < a: c = 4294967295 - a return (c + b) / float(delta) return (b - a) / float(delta)
python
{ "resource": "" }
q276138
Counter64
test
def Counter64(a, b, delta): """64bit counter aggregator with wrapping """ if b < a: c = 18446744073709551615 - a return (c + b) / float(delta) return (b - a) / float(delta)
python
{ "resource": "" }
q276139
average_duration
test
def average_duration(total_duration, visits): """ Method to calculate and format an average duration safely """ if not visits: seconds = 0 else: seconds = int(round(total_duration / Decimal(visits))) duration = timedelta(seconds=seconds) return str(duration)
python
{ "resource": "" }
q276140
TensorService.setupOutputs
test
def setupOutputs(self, config): """Setup output processors""" if self.proto == 'tcp': defaultOutput = { 'output': 'tensor.outputs.riemann.RiemannTCP', 'server': self.server, 'port': self.port } else: defaultOutp...
python
{ "resource": "" }
q276141
TensorService.setupSources
test
def setupSources(self, config): """Sets up source objects from the given config""" sources = config.get('sources', []) for source in sources: src = self.createSource(source) self.setupTriggers(source, src) self.sources.append(src)
python
{ "resource": "" }
q276142
TensorService.sendEvent
test
def sendEvent(self, source, events): """Callback that all event sources call when they have a new event or list of events """ if isinstance(events, list): self.eventCounter += len(events) else: self.eventCounter += 1 events = [events] ...
python
{ "resource": "" }
q276143
TensorService.sourceWatchdog
test
def sourceWatchdog(self): """Watchdog timer function. Recreates sources which have not generated events in 10*interval if they have watchdog set to true in their configuration """ for i, source in enumerate(self.sources): if not source.config.get('watchdog', False):...
python
{ "resource": "" }
q276144
ApacheLogParser._parse_format
test
def _parse_format(self, format): """ Converts the input format to a regular expression, as well as extracting fields Raises an exception if it couldn't compile the generated regex. """ format = format.strip() format = re.sub('[ \t]+',' ',format) ...
python
{ "resource": "" }
q276145
ApacheLogParser.parse
test
def parse(self, line): """ Parses a single line from the log file and returns a dictionary of it's contents. Raises and exception if it couldn't parse the line """ line = line.strip() match = self._regex.match(line) if match: data = {...
python
{ "resource": "" }
q276146
validate_expires_at
test
def validate_expires_at(form, field): """Validate that date is in the future.""" if form.accept.data: if not field.data or datetime.utcnow().date() >= field.data: raise validators.StopValidation(_( "Please provide a future date." )) if not field.data or \ ...
python
{ "resource": "" }
q276147
ApprovalForm.validate_message
test
def validate_message(form, field): """Validate message.""" if form.reject.data and not field.data.strip(): raise validators.ValidationError( _("You are required to provide message to the requester when" " you reject a request.") )
python
{ "resource": "" }
q276148
verify_token
test
def verify_token(): """Verify token and save in session if it's valid.""" try: from .models import SecretLink token = request.args['token'] # if the token is valid if token and SecretLink.validate_token(token, {}): # then save in session the token session[...
python
{ "resource": "" }
q276149
Device.name
test
def name(self): """ Return a basic meaningful name based on device type """ if ( self.device_type and self.device_type.code in (DeviceType.MOBILE, DeviceType.TABLET) ): return self.device else: return self.browser
python
{ "resource": "" }
q276150
_warn_node
test
def _warn_node(self, msg, *args, **kwargs): """Do not warn on external images.""" if not msg.startswith('nonlocal image URI found:'): _warn_node_old(self, msg, *args, **kwargs)
python
{ "resource": "" }
q276151
connect_receivers
test
def connect_receivers(): """Connect receivers to signals.""" request_created.connect(send_email_validation) request_confirmed.connect(send_confirmed_notifications) request_rejected.connect(send_reject_notification) # Order is important: request_accepted.connect(create_secret_link) request_ac...
python
{ "resource": "" }
q276152
create_secret_link
test
def create_secret_link(request, message=None, expires_at=None): """Receiver for request-accepted signal.""" pid, record = get_record(request.recid) if not record: raise RecordNotFound(request.recid) description = render_template( "zenodo_accessrequests/link_description.tpl", req...
python
{ "resource": "" }
q276153
send_accept_notification
test
def send_accept_notification(request, message=None, expires_at=None): """Receiver for request-accepted signal to send email notification.""" pid, record = get_record(request.recid) _send_notification( request.sender_email, _("Access request accepted"), "zenodo_accessrequests/emails/a...
python
{ "resource": "" }
q276154
send_confirmed_notifications
test
def send_confirmed_notifications(request): """Receiver for request-confirmed signal to send email notification.""" pid, record = get_record(request.recid) if record is None: current_app.logger.error("Cannot retrieve record %s. Emails not sent" % request.recid) ...
python
{ "resource": "" }
q276155
send_email_validation
test
def send_email_validation(request): """Receiver for request-created signal to send email notification.""" token = EmailConfirmationSerializer().create_token( request.id, dict(email=request.sender_email) ) pid, record = get_record(request.recid) _send_notification( request.sender_ema...
python
{ "resource": "" }
q276156
send_reject_notification
test
def send_reject_notification(request, message=None): """Receiver for request-rejected signal to send email notification.""" pid, record = get_record(request.recid) _send_notification( request.sender_email, _("Access request rejected"), "zenodo_accessrequests/emails/rejected.tpl", ...
python
{ "resource": "" }
q276157
_send_notification
test
def _send_notification(to, subject, template, **ctx): """Render a template and send as email.""" msg = Message( subject, sender=current_app.config.get('SUPPORT_EMAIL'), recipients=[to] ) msg.body = render_template(template, **ctx) send_email.delay(msg.__dict__)
python
{ "resource": "" }
q276158
SecretLink.create
test
def create(cls, title, owner, extra_data, description="", expires_at=None): """Create a new secret link.""" if isinstance(expires_at, date): expires_at = datetime.combine(expires_at, datetime.min.time()) with db.session.begin_nested(): obj = cls( owner=ow...
python
{ "resource": "" }
q276159
SecretLink.validate_token
test
def validate_token(cls, token, expected_data): """Validate a secret link token. Only queries the database if token is valid to determine that the token has not been revoked. """ data = SecretLinkFactory.validate_token( token, expected_data=expected_data ) ...
python
{ "resource": "" }
q276160
SecretLink.revoke
test
def revoke(self): """Revoken a secret link.""" if self.revoked_at is None: with db.session.begin_nested(): self.revoked_at = datetime.utcnow() link_revoked.send(self) return True return False
python
{ "resource": "" }
q276161
AccessRequest.create
test
def create(cls, recid=None, receiver=None, sender_full_name=None, sender_email=None, justification=None, sender=None): """Create a new access request. :param recid: Record id (required). :param receiver: User object of receiver (required). :param sender_full_name: Full na...
python
{ "resource": "" }
q276162
AccessRequest.get_by_receiver
test
def get_by_receiver(cls, request_id, user): """Get access request for a specific receiver.""" return cls.query.filter_by( id=request_id, receiver_user_id=user.id ).first()
python
{ "resource": "" }
q276163
AccessRequest.confirm_email
test
def confirm_email(self): """Confirm that senders email is valid.""" with db.session.begin_nested(): if self.status != RequestStatus.EMAIL_VALIDATION: raise InvalidRequestStateError(RequestStatus.EMAIL_VALIDATION) self.status = RequestStatus.PENDING reques...
python
{ "resource": "" }
q276164
AccessRequest.accept
test
def accept(self, message=None, expires_at=None): """Accept request.""" with db.session.begin_nested(): if self.status != RequestStatus.PENDING: raise InvalidRequestStateError(RequestStatus.PENDING) self.status = RequestStatus.ACCEPTED request_accepted.send...
python
{ "resource": "" }
q276165
AccessRequest.reject
test
def reject(self, message=None): """Reject request.""" with db.session.begin_nested(): if self.status != RequestStatus.PENDING: raise InvalidRequestStateError(RequestStatus.PENDING) self.status = RequestStatus.REJECTED request_rejected.send(self, message=me...
python
{ "resource": "" }
q276166
AccessRequest.create_secret_link
test
def create_secret_link(self, title, description=None, expires_at=None): """Create a secret link from request.""" self.link = SecretLink.create( title, self.receiver, extra_data=dict(recid=self.recid), description=description, expires_at=expires...
python
{ "resource": "" }
q276167
NistBeaconCrypto.get_hash
test
def get_hash( cls, version: str, frequency: int, timestamp: int, seed_value: str, prev_output: str, status_code: str, ) -> SHA512Hash: """ Given required properties from a NistBeaconValue, compute the SHA512H...
python
{ "resource": "" }
q276168
NistBeaconCrypto.verify
test
def verify( cls, timestamp: int, message_hash: SHA512Hash, signature: bytes, ) -> bool: """ Verify a given NIST message hash and signature for a beacon value. :param timestamp: The timestamp of the record being verified. :param message...
python
{ "resource": "" }
q276169
is_embargoed
test
def is_embargoed(record): """Template filter to check if a record is embargoed.""" return record.get('access_right') == 'embargoed' and \ record.get('embargo_date') and \ record.get('embargo_date') > datetime.utcnow().date()
python
{ "resource": "" }
q276170
access_request
test
def access_request(pid, record, template, **kwargs): """Create an access request.""" recid = int(pid.pid_value) datastore = LocalProxy( lambda: current_app.extensions['security'].datastore) # Record must be in restricted access mode. if record.get('access_right') != 'restricted' or \ ...
python
{ "resource": "" }
q276171
confirm
test
def confirm(pid, record, template, **kwargs): """Confirm email address.""" recid = int(pid.pid_value) token = request.view_args['token'] # Validate token data = EmailConfirmationSerializer.compat_validate_token(token) if data is None: flash(_("Invalid confirmation link."), category='da...
python
{ "resource": "" }
q276172
SSHClient._get_endpoint
test
def _get_endpoint(self): """ Creates a generic endpoint connection that doesn't finish """ return SSHCommandClientEndpoint.newConnection( reactor, b'/bin/cat', self.username, self.hostname, port=self.port, keys=self.keys, password=self.password, knownHosts = s...
python
{ "resource": "" }
q276173
Ordering.reverse
test
def reverse(self, col): """Get reverse direction of ordering.""" if col in self.options: if self.is_selected(col): return col if not self.asc else '-{0}'.format(col) else: return col return None
python
{ "resource": "" }
q276174
Ordering.selected
test
def selected(self): """Get column which is being order by.""" if self._selected: return self._selected if self.asc else \ "-{0}".format(self._selected) return None
python
{ "resource": "" }
q276175
QueryOrdering.items
test
def items(self): """Get query with correct ordering.""" if self.asc is not None: if self._selected and self.asc: return self.query.order_by(self._selected) elif self._selected and not self.asc: return self.query.order_by(desc(self._selected)) ...
python
{ "resource": "" }
q276176
FileVersionInfo.get_version
test
def get_version(self) -> str: """ Open the file referenced in this object, and scrape the version. :return: The version as a string, an empty string if there is no match to the magic_line, or any file exception messages encountered. """ try: ...
python
{ "resource": "" }
q276177
FileVersionInfo.set_version
test
def set_version(self, new_version: str): """ Set the version for this given file. :param new_version: The new version string to set. """ try: f = open(self.file_path, 'r') lines = f.readlines() f.close() except Exception as e: ...
python
{ "resource": "" }
q276178
Source._init_ssh
test
def _init_ssh(self): """ Configure SSH client options """ self.ssh_host = self.config.get('ssh_host', self.hostname) self.known_hosts = self.config.get('ssh_knownhosts_file', self.tensor.config.get('ssh_knownhosts_file', None)) self.ssh_keyfile = self.config.get('s...
python
{ "resource": "" }
q276179
Source.startTimer
test
def startTimer(self): """Starts the timer for this source""" self.td = self.t.start(self.inter) if self.use_ssh and self.ssh_connector: self.ssh_client.connect()
python
{ "resource": "" }
q276180
Source.tick
test
def tick(self): """Called for every timer tick. Calls self.get which can be a deferred and passes that result back to the queueBack method Returns a deferred""" if self.sync: if self.running: defer.returnValue(None) self.running = True ...
python
{ "resource": "" }
q276181
index
test
def index(): """List pending access requests and shared links.""" query = request.args.get('query', '') order = request.args.get('sort', '-created') try: page = int(request.args.get('page', 1)) per_page = int(request.args.get('per_page', 20)) except (TypeError, ValueError): a...
python
{ "resource": "" }
q276182
RiemannTCP.createClient
test
def createClient(self): """Create a TCP connection to Riemann with automatic reconnection """ server = self.config.get('server', 'localhost') port = self.config.get('port', 5555) failover = self.config.get('failover', False) self.factory = riemann.RiemannClientFactory(s...
python
{ "resource": "" }
q276183
RiemannTCP.stop
test
def stop(self): """Stop this client. """ self.t.stop() self.factory.stopTrying() self.connector.disconnect()
python
{ "resource": "" }
q276184
RiemannTCP.emptyQueue
test
def emptyQueue(self): """Remove all or self.queueDepth events from the queue """ if self.events: if self.queueDepth and (len(self.events) > self.queueDepth): # Remove maximum of self.queueDepth items from queue events = self.events[:self.queueDepth] ...
python
{ "resource": "" }
q276185
RiemannTCP.eventsReceived
test
def eventsReceived(self, events): """Receives a list of events and transmits them to Riemann Arguments: events -- list of `tensor.objects.Event` """ # Make sure queue isn't oversized if (self.maxsize < 1) or (len(self.events) < self.maxsize): self.events.exte...
python
{ "resource": "" }
q276186
RiemannUDP.createClient
test
def createClient(self): """Create a UDP connection to Riemann""" server = self.config.get('server', '127.0.0.1') port = self.config.get('port', 5555) def connect(ip): self.protocol = riemann.RiemannUDP(ip, port) self.endpoint = reactor.listenUDP(0, self.protocol)...
python
{ "resource": "" }
q276187
ElasticSearch.createClient
test
def createClient(self): """Sets up HTTP connector and starts queue timer """ server = self.config.get('server', 'localhost') port = int(self.config.get('port', 9200)) self.client = elasticsearch.ElasticSearch(self.url, self.user, self.password, self.index) ...
python
{ "resource": "" }
q276188
RiemannProtobufMixin.encodeEvent
test
def encodeEvent(self, event): """Adapts an Event object to a Riemann protobuf event Event""" pbevent = proto_pb2.Event( time=int(event.time), state=event.state, service=event.service, host=event.hostname, description=event.description, ...
python
{ "resource": "" }
q276189
RiemannProtobufMixin.encodeMessage
test
def encodeMessage(self, events): """Encode a list of Tensor events with protobuf""" message = proto_pb2.Msg( events=[self.encodeEvent(e) for e in events if e._type=='riemann'] ) return message.SerializeToString()
python
{ "resource": "" }
q276190
RiemannProtobufMixin.decodeMessage
test
def decodeMessage(self, data): """Decode a protobuf message into a list of Tensor events""" message = proto_pb2.Msg() message.ParseFromString(data) return message
python
{ "resource": "" }
q276191
RiemannProtobufMixin.sendEvents
test
def sendEvents(self, events): """Send a Tensor Event to Riemann""" self.pressure += 1 self.sendString(self.encodeMessage(events))
python
{ "resource": "" }
q276192
generate
test
def generate(ctx, url, *args, **kwargs): """ Generate preview for URL. """ file_previews = ctx.obj['file_previews'] options = {} metadata = kwargs['metadata'] width = kwargs['width'] height = kwargs['height'] output_format = kwargs['format'] if metadata: options['metada...
python
{ "resource": "" }
q276193
retrieve
test
def retrieve(ctx, preview_id, *args, **kwargs): """ Retreive preview results for ID. """ file_previews = ctx.obj['file_previews'] results = file_previews.retrieve(preview_id) click.echo(results)
python
{ "resource": "" }
q276194
Worker.r_q_send
test
def r_q_send(self, msg_dict): """Send message dicts through r_q, and throw explicit errors for pickle problems""" # Check whether msg_dict can be pickled... no_pickle_keys = self.invalid_dict_pickle_keys(msg_dict) if no_pickle_keys == []: self.r_q.put(msg_dict) ...
python
{ "resource": "" }
q276195
Worker.message_loop
test
def message_loop(self, t_q, r_q): """Loop through messages and execute tasks""" t_msg = {} while t_msg.get("state", "") != "__DIE__": try: t_msg = t_q.get(True, self.cycle_sleep) # Poll blocking self.task = t_msg.get("task", "") # __DIE__ has no task...
python
{ "resource": "" }
q276196
TaskMgrStats.log_time
test
def log_time(self): """Return True if it's time to log""" if self.hot_loop and self.time_delta >= self.log_interval: return True return False
python
{ "resource": "" }
q276197
SASLStateMachine.response
test
def response(self, payload): """ Send a response to the previously received challenge, with the given `payload`. The payload is encoded using base64 and transmitted to the server. Return the next state of the state machine as tuple (see :class:`SASLStateMachine` for deta...
python
{ "resource": "" }
q276198
SASLStateMachine.abort
test
def abort(self): """ Abort an initiated SASL authentication process. The expected result state is ``failure``. """ if self._state == SASLState.INITIAL: raise RuntimeError("SASL authentication hasn't started yet") if self._state == SASLState.SUCCESS_SIMULATE_C...
python
{ "resource": "" }
q276199
_saslprep_do_mapping
test
def _saslprep_do_mapping(chars): """ Perform the stringprep mapping step of SASLprep. Operates in-place on a list of unicode characters provided in `chars`. """ i = 0 while i < len(chars): c = chars[i] if stringprep.in_table_c12(c): chars[i] = "\u0020" elif st...
python
{ "resource": "" }