text stringlengths 0 828 |
|---|
Returns: |
bool. The return code:: |
True -- Loaded |
False -- Not Loaded |
"""""" |
if name is None: |
return True |
if isinstance(name, str): |
return (name in [x.__module__ for x in self]) |
if isinstance(name, Iterable): |
return set(name).issubset([x.__module__ for x in self]) |
return False" |
204,"def hook(self, function, dependencies=None): |
""""""Tries to load a hook |
Args: |
function (func): Function that will be called when the event is called |
Kwargs: |
dependencies (str): String or Iterable with modules whose hooks should be called before this one |
Raises: |
:class:TypeError |
Note that the dependencies are module-wide, that means that if |
`parent.foo` and `parent.bar` are both subscribed to `example` event |
and `child` enumerates `parent` as dependcy, **both** `foo` and `bar` |
must be called in order for the dependcy to get resolved. |
"""""" |
if not isinstance(dependencies, (Iterable, type(None), str)): |
raise TypeError(""Invalid list of dependencies provided!"") |
# Tag the function with its dependencies |
if not hasattr(function, ""__deps__""): |
function.__deps__ = dependencies |
# If a module is loaded before all its dependencies are loaded, put |
# it in _later list and don't load yet |
if self.isloaded(function.__deps__): |
self.append(function) |
else: |
self._later.append(function) |
# After each module load, retry to resolve dependencies |
for ext in self._later: |
if self.isloaded(ext.__deps__): |
self._later.remove(ext) |
self.hook(ext)" |
205,"def parse_from_json(json_str): |
"""""" |
Given a Unified Uploader message, parse the contents and return a |
MarketOrderList or MarketHistoryList instance. |
:param str json_str: A Unified Uploader message as a JSON string. |
:rtype: MarketOrderList or MarketHistoryList |
:raises: MalformedUploadError when invalid JSON is passed in. |
"""""" |
try: |
message_dict = json.loads(json_str) |
except ValueError: |
raise ParseError(""Mal-formed JSON input."") |
upload_keys = message_dict.get('uploadKeys', False) |
if upload_keys is False: |
raise ParseError( |
""uploadKeys does not exist. At minimum, an empty array is required."" |
) |
elif not isinstance(upload_keys, list): |
raise ParseError( |
""uploadKeys must be an array object."" |
) |
upload_type = message_dict['resultType'] |
try: |
if upload_type == 'orders': |
return orders.parse_from_dict(message_dict) |
elif upload_type == 'history': |
return history.parse_from_dict(message_dict) |
else: |
raise ParseError( |
'Unified message has unknown upload_type: %s' % upload_type) |
except TypeError as exc: |
# MarketOrder and HistoryEntry both raise TypeError exceptions if |
# invalid input is encountered. |
raise ParseError(exc.message)" |
206,"def encode_to_json(order_or_history): |
"""""" |
Given an order or history entry, encode it to JSON and return. |
:type order_or_history: MarketOrderList or MarketHistoryList |
:param order_or_history: A MarketOrderList or MarketHistoryList instance to |
encode to JSON. |
:rtype: str |
:return: The encoded JSON string. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.