API¶
network¶
- class more_ds.network.URL¶
Helper class for conveniently constructing URLs.
To that end the
/operator has been overloaded to append path elements. Similarly the//operator has been overloaded to easily add a query string to theURL.Being a subclass of
str, instances ofURLcan be used anywhere astris expected.IMPORTANT No form of verification is performed. Meaning for instance that any string, not only those that actually make up an
URL, can be use to initialize anURLinstance. And one can add multiple query strings to anURLinstance leading to an improperly formattedURL.Example:
>>> from more_ds.network import URL >>> base_url = URL("http://example.org/") >>> api_url = base_url / "api" >>> url = api_url / "ip" / "address" // dict(version=4) >>> print(url) http://example.org/api/ip/address?version=4
- __truediv__(path: object) → more_ds.network.url.URL¶
Append path element to the URL object.
It prevents accidental inclusion of too many slashes between the appended
pathelements should theURLend in a slash and/or thepathelement start with a slash.- Parameters
path – path element to append
- Returns
A new
URLobject with thepathelement appended.
- __floordiv__(query: Mapping) → more_ds.network.url.URL¶
Append a query string to the URL.
- Parameters
query – Mapping of values that should be converted to a query string.
- Returns
a new
URLobject with thequeryappended as a query string.
time¶
- class more_ds.time.Timer¶
Simple context manager for timing blocks of code.
With
Timeryou can create a runtime context in which a block of code code will be timed. When runtime context is exited, theTimerinstance responsible for the runtime context can be queried for thedurationorelapsedtime.Examples:
from time import sleep from more_ds.time import Timer with Timer() as t: # sleep for half a second sleep(.5) print(t.elapsed) # -> 0:00:00.501864