text stringlengths 0 828 |
|---|
:arg str name: name for the metric |
:arg int count: user-supplied number of items, defaults to 1 |
"""""" |
t = time.time() |
try: |
yield |
finally: |
metric(name, count, time.time() - t)" |
396,"def import_from_string(import_string): |
"""""" |
Import a class from a string |
import_string - string path to module to import using dot notation (foo.bar) |
"""""" |
import_split = import_string.split(""."") |
import_class = import_split[-1] |
module_path = ""."".join(import_split[:-1]) |
mod = __import__(module_path, fromlist=[import_class]) |
klass = getattr(mod, import_class) |
return klass" |
397,"def send(self,message,message_type,topic=''): |
"""""" |
Send the message on the socket. |
Args: |
- message: the message to publish |
- message_type: the type of message being sent |
- topic: the topic on which to send the message. Defaults to ''. |
"""""" |
if message_type == RAW: |
self._sock.send(message) |
elif message_type == PYOBJ: |
self._sock.send_pyobj(message) |
elif message_type == JSON: |
self._sock.send_json(message) |
elif message_type == MULTIPART: |
self._sock.send_multipart([topic, message]) |
elif message_type == STRING: |
self._sock.send_string(message) |
elif message_type == UNICODE: |
self._sock.send_unicode(message) |
else: |
raise Exception(""Unknown message type %s""%(message_type,))" |
398,"def receive(self,message_type): |
"""""" |
Receive the message of the specified type and retun |
Args: |
- message_type: the type of the message to receive |
Returns: |
- the topic of the message |
- the message received from the socket |
"""""" |
topic = None |
message = None |
if message_type == RAW: |
message = self._sock.recv(flags=zmq.NOBLOCK) |
elif message_type == PYOBJ: |
message = self._sock.recv_pyobj(flags=zmq.NOBLOCK) |
elif message_type == JSON: |
message = self._sock.recv_json(flags=zmq.NOBLOCK) |
elif message_type == MULTIPART: |
data = self._sock.recv_multipart(flags=zmq.NOBLOCK) |
message = data[1] |
topic = data[0] |
elif message_type == STRING: |
message = self._sock.recv_string(flags=zmq.NOBLOCK) |
elif message_type == UNICODE: |
message = self._sock.recv_unicode(flags=zmq.NOBLOCK) |
else: |
raise Exception(""Unknown message type %s""%(self._message_type,)) |
return (topic, message)" |
399,"def dynamic_exec(code, resolve, assign=None, delete=None, automatic_builtins=True, |
filename=None, module_name=None, _type='exec'): |
"""""" |
Transforms the Python source code *code* and evaluates it so that the |
*resolve* and *assign* functions are called respectively for when a global |
variable is access or assigned. |
If *resolve* is a mapping, *assign* must be omitted. #KeyError#s raised by |
the mapping are automatically converted to #NameError#s. |
Otherwise, *resolve* and *assign* must be callables that have the same |
interface as `__getitem__()`, and `__setitem__()`. If *assign* is omitted |
in that case, assignments will be redirected to a separate dictionary and |
keys in that dictionary will be checked before continuing with the *resolve* |
callback. |
"""""" |
parse_filename = filename or '<string>' |
ast_node = transform(ast.parse(code, parse_filename, mode=_type)) |
code = compile(ast_node, parse_filename, _type) |
if hasattr(resolve, '__getitem__'): |
if assign is not None: |
raise TypeError('""assign"" parameter specified where ""resolve"" is a mapping') |
if delete is not None: |
raise TypeError('""delete"" parameter specified where ""resolve"" is a mapping') |
input_mapping = resolve |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.