karrio 2023.1.11__py3-none-any.whl → 2023.1.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- karrio/core/models.py +3 -3
- karrio/core/units.py +8 -0
- karrio/core/utils/helpers.py +17 -3
- karrio/lib.py +3 -8
- {karrio-2023.1.11.dist-info → karrio-2023.1.12.dist-info}/METADATA +1 -1
- {karrio-2023.1.11.dist-info → karrio-2023.1.12.dist-info}/RECORD +8 -8
- {karrio-2023.1.11.dist-info → karrio-2023.1.12.dist-info}/WHEEL +0 -0
- {karrio-2023.1.11.dist-info → karrio-2023.1.12.dist-info}/top_level.txt +0 -0
karrio/core/models.py
CHANGED
@@ -410,16 +410,16 @@ class DocumentUploadRequest:
|
|
410
410
|
"""shipment document upload request unified data type."""
|
411
411
|
|
412
412
|
document_files: List[DocumentFile] = JList[DocumentFile, REQUIRED]
|
413
|
-
options: Dict = {}
|
414
|
-
reference: str = None
|
415
413
|
tracking_number: str = None
|
414
|
+
reference: str = None
|
415
|
+
options: Dict = {}
|
416
416
|
|
417
417
|
|
418
418
|
@attr.s(auto_attribs=True)
|
419
419
|
class DocumentDetails:
|
420
420
|
"""Karrio unified uploaded document id info data type."""
|
421
421
|
|
422
|
-
|
422
|
+
doc_id: str
|
423
423
|
file_name: str
|
424
424
|
|
425
425
|
|
karrio/core/units.py
CHANGED
@@ -887,6 +887,14 @@ class ShippingOptions(Options):
|
|
887
887
|
def signature_confirmation(self) -> utils.OptionEnum:
|
888
888
|
return self[ShippingOption.signature_confirmation.name]
|
889
889
|
|
890
|
+
@property
|
891
|
+
def doc_files(self) -> utils.OptionEnum:
|
892
|
+
return self[ShippingOption.doc_files.name]
|
893
|
+
|
894
|
+
@property
|
895
|
+
def doc_references(self) -> utils.OptionEnum:
|
896
|
+
return self[ShippingOption.doc_references.name]
|
897
|
+
|
890
898
|
|
891
899
|
class CustomsOption(utils.Enum):
|
892
900
|
"""common shipment customs identifiers"""
|
karrio/core/utils/helpers.py
CHANGED
@@ -2,9 +2,10 @@ import io
|
|
2
2
|
import re
|
3
3
|
import ssl
|
4
4
|
import uuid
|
5
|
+
import string
|
6
|
+
import base64
|
5
7
|
import asyncio
|
6
8
|
import logging
|
7
|
-
import base64
|
8
9
|
import urllib.parse
|
9
10
|
from PyPDF2 import PdfMerger
|
10
11
|
from PIL import Image, ImageFile
|
@@ -26,6 +27,15 @@ def identity(value: Any) -> Any:
|
|
26
27
|
return value
|
27
28
|
|
28
29
|
|
30
|
+
def failsafe(callable: Callable[[], T], warning: str = None) -> T:
|
31
|
+
try:
|
32
|
+
return callable()
|
33
|
+
except Exception as e:
|
34
|
+
if warning:
|
35
|
+
logger.warning(string.Template(warning).substitute(error=e))
|
36
|
+
return None
|
37
|
+
|
38
|
+
|
29
39
|
def to_buffer(encoded_file: str, **kwargs) -> io.BytesIO:
|
30
40
|
content = base64.b64decode(encoded_file, **kwargs)
|
31
41
|
buffer = io.BytesIO()
|
@@ -107,7 +117,11 @@ def bundle_base64(base64_strings: List[str], format: str = "PDF") -> str:
|
|
107
117
|
|
108
118
|
|
109
119
|
def decode_bytes(byte):
|
110
|
-
return
|
120
|
+
return (
|
121
|
+
failsafe(lambda: byte.decode("utf-8")) or
|
122
|
+
failsafe(lambda: byte.decode("ISO-8859-1")) or
|
123
|
+
byte.decode("utf-8")
|
124
|
+
)
|
111
125
|
|
112
126
|
|
113
127
|
def process_request(
|
@@ -170,7 +184,7 @@ def process_error(
|
|
170
184
|
if on_error is not None:
|
171
185
|
_error = on_error(error)
|
172
186
|
else:
|
173
|
-
_error = error.read()
|
187
|
+
_error = decode_bytes(error.read())
|
174
188
|
|
175
189
|
if trace:
|
176
190
|
trace({"request_id": request_id, "error": _error}, "error")
|
karrio/lib.py
CHANGED
@@ -65,7 +65,7 @@ def text(
|
|
65
65
|
separator: str = None,
|
66
66
|
) -> typing.Optional[str]:
|
67
67
|
"""Returns a joined text
|
68
|
-
|
68
|
+
|
69
69
|
Example:
|
70
70
|
result1 = text("string text 1", "string text 2")
|
71
71
|
print(result1) # "string text 1 string text 2"
|
@@ -87,7 +87,7 @@ def text(
|
|
87
87
|
|
88
88
|
if _text is None:
|
89
89
|
return None
|
90
|
-
|
90
|
+
|
91
91
|
return typing.cast(str, _text[0:max] if max else _text)
|
92
92
|
|
93
93
|
|
@@ -622,9 +622,4 @@ def failsafe(callable: typing.Callable[[], T], warning: str = None) -> T:
|
|
622
622
|
Only use it when you are running something unstable that you
|
623
623
|
don't mind if it fails.
|
624
624
|
"""
|
625
|
-
|
626
|
-
return callable()
|
627
|
-
except Exception as e:
|
628
|
-
if warning:
|
629
|
-
logger.warning(string.Template(warning).substitute(error=e))
|
630
|
-
return None
|
625
|
+
return utils.failsafe(callable, warning=warning)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
karrio/__init__.py,sha256=MGaZGiMfGOpYY5gTQaOT-FgpyAmRoBio8dfXl1IcRWA,3149
|
2
|
-
karrio/lib.py,sha256=
|
2
|
+
karrio/lib.py,sha256=1ucAphYpt2aeOGHKeq2c2rEXvsosfWn9TC8tN4U_7JE,17241
|
3
3
|
karrio/references.py,sha256=0z-b2U2Z8ghhvC-hH6XpMhiVKrGcizyq5FTD4G1XsRg,4673
|
4
4
|
karrio/addons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
karrio/addons/label.py,sha256=WwC1o97Ztyj3kRNTlAkHmYh4It7dC7l8bsC3fc-5yMA,10316
|
@@ -14,14 +14,14 @@ karrio/api/proxy.py,sha256=Mx5tpcL0L_02lIZ84AvnEfroVu5Qi22iz7AVueX4YjI,6320
|
|
14
14
|
karrio/core/__init__.py,sha256=BboTt3huAYrsqcTcaq1lFX5O4uKiIi2cpWEXp68ItMo,71
|
15
15
|
karrio/core/errors.py,sha256=iMwiwCwK0eiYzk5KJ9Qu86JMWpymw1zDCvmqY67ghSw,3006
|
16
16
|
karrio/core/metadata.py,sha256=kJUov6vdVZVrNaRF-J0RP4Papb8hZifAVY97TxcYQO0,1029
|
17
|
-
karrio/core/models.py,sha256=
|
17
|
+
karrio/core/models.py,sha256=OuSW62aEdzvOspSKXsssudemeQ-LZ7BiYKg4v-E3_j4,9594
|
18
18
|
karrio/core/settings.py,sha256=mjL6vtKZnjK7ITcmkxvmOZHshHc7LDuhseF5wAojt_4,518
|
19
|
-
karrio/core/units.py,sha256
|
19
|
+
karrio/core/units.py,sha256=iCBA0dMwQfVwa1ZmPkpvmDSCd9gO1hoVn3yTNcbWbuU,54795
|
20
20
|
karrio/core/utils/__init__.py,sha256=537Hel7VeqWPbcFp41Dr5E-pzOCEHHD5oqhuA58X4P4,695
|
21
21
|
karrio/core/utils/datetime.py,sha256=aFMqLB_AdRGM0By2TO8mYce-UlqExf_J2s2eLNtDClY,2311
|
22
22
|
karrio/core/utils/dict.py,sha256=fUsyMwRduh3qJ6D6Vf4LUVcljEqDHJVn8Av9x4rUadg,2312
|
23
23
|
karrio/core/utils/enum.py,sha256=qCrqP49wXyypfQ7rw4kFGjJ6rawptOxq_RPwqaz09dk,4420
|
24
|
-
karrio/core/utils/helpers.py,sha256=
|
24
|
+
karrio/core/utils/helpers.py,sha256=wqrMYUX2_JpQbXBd0eLnmE1R3I0qKDbGJ2EoR0Wv4wc,7593
|
25
25
|
karrio/core/utils/log.py,sha256=G0JqUqNiS7JwkFMurtHtbxa42miAs28dPfNZZdlZid4,434
|
26
26
|
karrio/core/utils/number.py,sha256=z455Zbx5V92Ofo8PEaC_UEfmVEwnb-nq7fIoSeApz4o,1176
|
27
27
|
karrio/core/utils/pipeline.py,sha256=sr4YCkqTeJjXPPPOCXZqzljn9OZyFqRPhCqGr1WTt74,1237
|
@@ -44,7 +44,7 @@ karrio/universal/providers/rating/utils.py,sha256=zNbBahziUqbh3g-Uo7gbJ4jXmp7cWQ
|
|
44
44
|
karrio/universal/providers/shipping/__init__.py,sha256=JRcfJWSeDSjO2g2fRnLgBurBXn01nVpdi21ShxLpG34,188
|
45
45
|
karrio/universal/providers/shipping/shipment.py,sha256=FwpIAaRMLhwINNRGSRTCcSB0xmPS2yGGbGHNAf4O8Cg,1468
|
46
46
|
karrio/universal/providers/shipping/utils.py,sha256=1LuO31RMhpUls6-h5xhWkfky4G7tdWmGKmRhLkj-e98,593
|
47
|
-
karrio-2023.1.
|
48
|
-
karrio-2023.1.
|
49
|
-
karrio-2023.1.
|
50
|
-
karrio-2023.1.
|
47
|
+
karrio-2023.1.12.dist-info/METADATA,sha256=-vHB_oDdaKQdAsefKAhQMQoRG8SScrGqoGq3qSoO5a0,4706
|
48
|
+
karrio-2023.1.12.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
49
|
+
karrio-2023.1.12.dist-info/top_level.txt,sha256=mfkVZXzNuVRmA7NRlck_Ub-C8Zgtqxbx3gX1Rq_W-i0,7
|
50
|
+
karrio-2023.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|