utils
pymonzo utils.
WSGIApp
Bare-bones WSGI app made for retrieving the OAuth callback.
Source code in pymonzo/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
__call__(environ, start_response)
Implement WSGI interface and save the URL of the callback.
Source code in pymonzo/utils.py
89 90 91 92 93 94 95 96 97 98 | |
empty_dict_to_none(v)
Return None if the passed value is an empty dict, otherwise do nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v |
Any
|
Value to check. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Passed value or |
Source code in pymonzo/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 | |
empty_str_to_none(v)
Return None passed value is an empty string, otherwise do nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v |
Any
|
Value to check. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Passed value or |
Source code in pymonzo/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
format_currency(amount, currency)
Format passed amount with two decimal places.
Used as a fallback when babel isn't available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount |
float
|
Amount of money. |
required |
currency |
str
|
Money currency. Unused here, but needed to match the signature
with |
required |
Returns:
| Type | Description |
|---|---|
str
|
Passed amount with two decimal places. |
Source code in pymonzo/utils.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
format_datetime(dt)
Format passed datetime in user locale.
Used as a fallback when babel isn't available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt |
datetime
|
Datetime to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Passed |
Source code in pymonzo/utils.py
54 55 56 57 58 59 60 61 62 63 64 65 | |
get_authorization_response_url(host, port)
Get OAuth authorization response URL.
It's done by creating a bare-bones HTTP server and retrieving a single request, the OAuth callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host |
str
|
temporary HTTP server host name. |
required |
port |
int
|
temporary HTTP server port. |
required |
Returns:
| Type | Description |
|---|---|
str
|
URL of the OAuth authorization response. |
Source code in pymonzo/utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
n_days_ago(n)
Return datetime that was n days ago.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n |
int
|
Number of days to go back. |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Datetime that was |
Source code in pymonzo/utils.py
10 11 12 13 14 15 16 17 18 19 20 21 | |