text
stringlengths 0
828
|
---|
Dispatches the given event. |
It is the duty of this method to set the target of the dispatched event by calling |
`event.set_target(self)`. |
Args: |
event (Event): The event to dispatch. Must not be `None`. |
Raises: |
TypeError: If the event is `None` or its type is incorrect. |
"""""" |
# Set the target of the event if it doesn't have one already. It could happen that |
# we are simply redispatching an event. |
if event.target is None: |
event.set_target(self) |
listeners: dict[types.MethodType, bool] = self._registered_listeners.get(event.type) |
if listeners is None: |
return |
for listener in listeners: |
listener(event)" |
4794,"def remove_event_listener(self, event_type: str, event_handler: types.MethodType) -> None: |
"""""" |
Removes the given event listener registered on the dispatcher for the given event type. |
Args: |
event_type (str): The type of the event to remove the event handler from. |
Must not be `None` or empty string. |
event_handler (types.MethodType): The event handler to remove from the given event |
type of the dispatcher. Must not be `None`. |
Raises: |
ValueError: If any of the parameters are invalid. |
"""""" |
# TODO: we should also accept types.FunctionType, |
# don't forget the documentation here and in the interface. |
if not isinstance(event_type, str) or event_type == """" or\ |
not isinstance(event_handler, types.MethodType): |
raise ValueError(""Invalid arguments: {}, {}"".format(event_type, event_handler)) |
listeners: dict[types.MethodType, bool] = self._registered_listeners.get(event_type) |
listener: types.MethodType = None if listeners is None else listeners.get(event_handler) |
if listener is not None: |
del listeners[event_handler]" |
4795,"def set_target(self, target: EventDispatcherBase) -> None: |
"""""" |
This method should be called by the event dispatcher that dispatches this event |
to set its target property. |
Args: |
target (EventDispatcherBase): The event dispatcher that will dispatch this event. |
Raises: |
PermissionError: If the target property of the event has already been set. |
TypeError: If `target` is not an `EventDispatcherBase` instance. |
"""""" |
if self._target is not None: |
raise PermissionError(""The target property already has a valid value."") |
if not isinstance(target, EventDispatcherBase): |
raise TypeError(""Invalid target type: {}"".format(target)) |
self._target = target" |
4796,"def download_url(url, content_type=None, download_to_file=None, |
retry_count=10, timeout=10.0): |
"""""" |
Will download a file from given URL (either local or external) to the |
desired path (or generate one if none is given). Local files are copied |
directly. |
The function will retry a number of times based on retry_count (default 10) |
parameter and sleeps a number of seconds based on given timeout |
(default 10.0 sec) after each failed request. |
Returns the path to the downloaded file if successful. |
Otherwise an exception is raised. |
Given a content_type and an external URL, the function will make sure |
that the desired content_type is equal to the content-type of returned |
file. |
@param url: where the file lives on the interwebs |
@type url: string |
@param content_type: desired content_type to check for in external URLs. |
(optional) |
@type content_type: string |
@param download_to_file: where the file should live after download. |
(optional) |
@type download_to_file: string |
@param retry_count: number of times to retry. Defaults to 10. |
(optional) |
@type retry_count: int |
@param timeout: number of seconds to sleep between attempts. |
Defaults to 10.0 seconds. (optional) |
@type timeout: float |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.