text stringlengths 0 828 |
|---|
if not isinstance(sys.stdout, StreamHooks): |
sys.stdout = StreamHooks(sys.stdout) |
ref = weakref.ref(func) |
if ref not in sys.stdout.hooks: |
sys.stdout.hooks.append(ref)" |
3710,"def setup(): |
"""""" |
Initializes the hook queues for the sys module. This method will |
automatically be called on the first registration for a hook to the system |
by either the registerDisplay or registerExcept functions. |
"""""" |
global _displayhooks, _excepthooks |
if _displayhooks is not None: |
return |
_displayhooks = [] |
_excepthooks = [] |
# store any current hooks |
if sys.displayhook != sys.__displayhook__: |
_displayhooks.append(weakref.ref(sys.displayhook)) |
if sys.excepthook != sys.__excepthook__: |
_excepthooks.append(weakref.ref(sys.excepthook)) |
# replace the current hooks |
sys.displayhook = displayhook |
sys.excepthook = excepthook" |
3711,"def unregisterStdErr(func): |
"""""" |
Un-registers a function from the print hook queue. |
Look at the sys.displayhook documentation for more information. |
:param func | <callable> |
"""""" |
try: |
sys.stderr.hooks.remove(weakref.ref(func)) |
except (AttributeError, ValueError): |
pass" |
3712,"def unregisterStdOut(func): |
"""""" |
Un-registers a function from the print hook queue. |
Look at the sys.displayhook documentation for more information. |
:param func | <callable> |
"""""" |
try: |
sys.stdout.hooks.remove(weakref.ref(func)) |
except (AttributeError, ValueError): |
pass" |
3713,"def _parse_iso8601(text): |
"""""" |
Maybe parse an ISO8601 datetime string into a datetime. |
:param text: Either a ``unicode`` string to parse or any other object |
(ideally a ``datetime`` instance) to pass through. |
:return: A ``datetime.datetime`` representing ``text``. Or ``text`` if it |
was anything but a ``unicode`` string. |
"""""" |
if isinstance(text, unicode): |
try: |
return parse_iso8601(text) |
except ValueError: |
raise CheckedValueTypeError( |
None, (datetime,), unicode, text, |
) |
# Let pyrsistent reject it down the line. |
return text" |
3714,"def from_path(cls, spec_path): |
"""""" |
Load a specification from a path. |
:param FilePath spec_path: The location of the specification to read. |
"""""" |
with spec_path.open() as spec_file: |
return cls.from_document(load(spec_file))" |
3715,"def add_behavior_for_pclass(self, definition, cls): |
"""""" |
Define an additional base class for the Python class created for a |
particular definition. |
:param unicode definition: The definition the Python class for which |
the base class will be included. |
:param type cls: The additional base class. |
:raise ValueError: If a Python class for the given definition has |
already been created. Behavior cannot be retroactively added to a |
Python class. All behaviors must be registered before the first |
call to ``pclass_for_definition`` for a particular definition. |
:return: ``None`` |
"""""" |
if definition in self._pclasses: |
raise AlreadyCreatedClass(definition) |
if definition not in self.definitions: |
raise NoSuchDefinition(definition) |
self._behaviors.setdefault(definition, []).append(cls)" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.