Helper functions¶
Helper functions of the module, we added them for documentation purpose and we think thath it may be useful for scripting and prototyping
App Utils¶
app_utils
¶
Classes:
-
UtilsError–Exception de base des fonctions du module Utils
Functions:
-
get_app_version–Construit le metadata de l'application en cours
-
to_bool–Convertit une cdc en booléen selon un mapping simple
-
to_date–Retourne une date depuis un string, format dd/mm/yyyy ou dd-mm-yyyy ou dd.mm.yyyy
-
to_datetime–Retourne un datetime depuis un string, format dd/mm/yyyy ou dd-mm-yyy
-
to_float–Valide et convertit un texte qui représente un nombre rationnel.
-
to_int–Valide un texte qui représente un nombre entier.
UtilsError
¶
Exception de base des fonctions du module Utils
get_app_version
¶
get_app_version() -> dict
Construit le metadata de l'application en cours
Source code in pycalendar_api/utils/app_utils.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
to_bool
¶
Convertit une cdc en booléen selon un mapping simple
Parameters:
-
(value¶`str`) –Une valeur décrivant un état booléan
Returns:
-
bool–bool: True ou False
Source code in pycalendar_api/utils/app_utils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
to_date
¶
Retourne une date depuis un string, format dd/mm/yyyy ou dd-mm-yyyy ou dd.mm.yyyy
Source code in pycalendar_api/utils/app_utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
to_datetime
¶
Retourne un datetime depuis un string, format dd/mm/yyyy ou dd-mm-yyy
Source code in pycalendar_api/utils/app_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
to_float
¶
to_float(float_value: str) -> float
Valide et convertit un texte qui représente un nombre rationnel.
Parameters:
-
(float_value¶`str`) –Valeur en texte
Returns:
-
float–float: Le nombre en unité de base
Source code in pycalendar_api/utils/app_utils.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
to_int
¶
Valide un texte qui représente un nombre entier.
Parameters:
-
(int_value¶`str`) –nombre entier en texte
Returns:
-
int–int: Le nombre entier en unité de base
Source code in pycalendar_api/utils/app_utils.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
HTTP Client¶
http_client
¶
Functions:
-
add_timestamp_async–httpx.AsyncClientevent hooks must be coroutines -
build_ssl_context–Build the TLS context of the transport
-
get_http_client–Build the HTTP client. The options match the
[http_client]section of the configuration (HTTPClientConfig) -
get_http_client_async–Build the async HTTP client. Same options as
get_http_client -
resolve_proxy–Proxy used to reach
base_url
add_timestamp_async
async
¶
add_timestamp_async(request)
httpx.AsyncClient event hooks must be coroutines
Source code in pycalendar_api/utils/http_client.py
19 20 21 | |
build_ssl_context
¶
build_ssl_context(verify: bool | str = True, cert: str = None, cert_key: str = None, trust_env: bool = True) -> SSLContext
Build the TLS context of the transport
Parameters:
-
(verify¶bool | str, default:True) –Verify the server certificate. A path to a CA bundle file (or directory) replaces the default CAs
-
(cert¶str, default:None) –Client certificate file (PEM), for mutual TLS. May also contain the private key
-
(cert_key¶str, default:None) –Private key file of
cert, when not included in it -
(trust_env¶bool, default:True) –Use the
SSL_CERT_FILE/SSL_CERT_DIRenvironment variables whenverify=True
Returns:
-
SSLContext–ssl.SSLContext: TLS context
Source code in pycalendar_api/utils/http_client.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
get_http_client
¶
get_http_client(base_url: str = '', headers: dict = None, cookies: dict = None, default_encoding: str = 'utf-8', timeout: float = 10, read_timeout: float = None, retries: int = 3, verify: bool | str = True, cert: str = None, cert_key: str = None, proxy: str = None, trust_env: bool = True, follow_redirects: bool = True, transport: BaseTransport = None, **client_kwargs) -> Client
Build the HTTP client. The options match the [http_client] section of the configuration (HTTPClientConfig)
Parameters:
-
(base_url¶str, default:'') –Base URL of the requests
-
(headers¶dict, default:None) –Headers merged with the default ones
-
(timeout¶float, default:10) –Connect/write/pool timeout in seconds
-
(read_timeout¶float, default:None) –Read timeout in seconds. Default:
timeout * 5 -
(retries¶int, default:3) –Retries on connection errors
-
(verify¶bool | str, default:True) –Verify the server certificate, or path to a CA bundle. See
build_ssl_context -
(cert¶str, default:None) –Client certificate file (PEM)
-
(cert_key¶str, default:None) –Private key file of
cert -
(proxy¶str, default:None) –Proxy URL (ie:
http://user:pass@proxy:3128). Seeresolve_proxy -
(trust_env¶bool, default:True) –Use the proxy and certificates environment variables
-
(transport¶BaseTransport, default:None) –Custom transport (tests...). Replaces the one built with
retries,verify,certandproxy -
–**client_kwargs¶Extra
httpx.Clientarguments (limits,auth,event_hooks...)
Returns:
-
Client–httpx.Client: Configured client
Source code in pycalendar_api/utils/http_client.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
get_http_client_async
¶
get_http_client_async(base_url: str = '', headers: dict = None, cookies: dict = None, default_encoding: str = 'utf-8', timeout: float = 10, read_timeout: float = None, retries: int = 3, verify: bool | str = True, cert: str = None, cert_key: str = None, proxy: str = None, trust_env: bool = True, follow_redirects: bool = True, transport: AsyncBaseTransport = None, **client_kwargs) -> AsyncClient
Build the async HTTP client. Same options as get_http_client
Returns:
-
AsyncClient–httpx.AsyncClient: Configured async client
Source code in pycalendar_api/utils/http_client.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
resolve_proxy
¶
Proxy used to reach base_url
An explicit proxy always wins. Otherwise, when trust_env is True, the standard environment variables
HTTPS_PROXY / HTTP_PROXY / ALL_PROXY are used, unless the host is excluded by NO_PROXY.
Returns:
-
str | None–str | None: Proxy URL or None for a direct connection
Source code in pycalendar_api/utils/http_client.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |