Skip to content

Commit 6c28b14

Browse files
committed
fix: multipart testing
1 parent 4e673d0 commit 6c28b14

File tree

8 files changed

+58
-48
lines changed

8 files changed

+58
-48
lines changed

appwrite/client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def __init__(self):
1212
self._endpoint = 'https://cloud.appwrite.io/v1'
1313
self._global_headers = {
1414
'content-type': '',
15-
'user-agent' : 'AppwritePythonSDK/7.0.0-rc1 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
15+
'user-agent' : 'AppwritePythonSDK/7.0.0 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
1616
'x-sdk-name': 'Python',
1717
'x-sdk-platform': 'server',
1818
'x-sdk-language': 'python',
19-
'x-sdk-version': '7.0.0-rc1',
19+
'x-sdk-version': '7.0.0',
2020
'X-Appwrite-Response-Format' : '1.6.0',
2121
}
2222

@@ -96,9 +96,9 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
9696
if isinstance(data[key], Payload):
9797
if data[key].filename:
9898
files[key] = (data[key].filename, data[key].to_binary())
99+
del data[key]
99100
else:
100-
data[key] = data[key].to_binary()
101-
del data[key]
101+
data[key] = data[key].to_string()
102102
data = self.flatten(data, stringify=stringify)
103103

104104
response = None

appwrite/multipart.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from email.parser import BytesParser
22
from email.policy import default
33
from .payload import Payload
4+
import json
45

56
class MultipartParser:
67
def __init__(self, multipart_bytes, content_type):
@@ -38,7 +39,7 @@ def to_dict(self):
3839
result[name] = Payload.from_binary(part["contents"])
3940
elif name == "responseHeaders":
4041
headers_str = part["contents"].decode('utf-8', errors='replace')
41-
result[name] = dict(line.split(": ", 1) for line in headers_str.split("\r\n") if line)
42+
result[name] = json.loads(headers_str)
4243
elif name == "responseStatusCode":
4344
result[name] = int(part["contents"])
4445
elif name == "duration":

appwrite/payload.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,52 @@
22
import os, json
33

44
class Payload:
5-
size: int
65
filename: Optional[str] = None
76

87
_path: Optional[str] = None
98
_data: Optional[bytes] = None
9+
_size: int = 0
10+
11+
@property
12+
def size(self) -> int:
13+
return self._size
1014

1115
def __init__(self, path: Optional[str] = None, data: Optional[bytes] = None, filename: Optional[str] = None):
12-
if not path and not data:
16+
if path is None and data is None:
1317
raise ValueError("One of path or data must be provided")
1418

1519
self._path = path
1620
self._data = data
1721

1822
self.filename = filename
19-
if not self._data:
20-
self.size = os.path.getsize(self._path)
23+
if self._data is None:
24+
self._size = os.path.getsize(self._path)
2125
else:
22-
self.size = len(self._data)
23-
26+
self._size = len(self._data)
27+
2428
def to_binary(self, offset: Optional[int] = 0, length: Optional[int] = None) -> bytes:
25-
if not length:
26-
length = self.size
27-
28-
if not self._data:
29+
if length is None:
30+
length = self._size
31+
32+
if self._data is None:
2933
with open(self._path, 'rb') as f:
3034
f.seek(offset)
3135
return f.read(length)
32-
36+
3337
return self._data[offset:offset + length]
34-
35-
def to_string(self) -> str:
36-
return str(self.to_binary())
38+
39+
def to_string(self, encoding="utf-8") -> str:
40+
return self.to_binary().decode(encoding)
41+
42+
def __str__(self) -> str:
43+
return self.to_string()
3744

3845
def to_json(self) -> Dict[str, Any]:
3946
return json.loads(self.to_string())
40-
41-
def to_file(self, path: str) -> None: # in the client SDKs, this is def to_file() -> File:
47+
48+
def to_file(self, path: str) -> None:
49+
os.makedirs(os.path.dirname(path), exist_ok=True)
50+
4251
with open(path, 'wb') as f:
4352
return f.write(self.to_binary())
4453

@@ -49,7 +58,7 @@ def from_binary(cls, data: bytes, filename: Optional[str] = None) -> 'Payload':
4958
@classmethod
5059
def from_string(cls, data: str) -> 'Payload':
5160
return cls(data=data.encode())
52-
61+
5362
@classmethod
5463
def from_file(cls, path: str, filename: Optional[str] = None) -> 'Payload':
5564
if not os.path.exists(path):
@@ -59,5 +68,5 @@ def from_file(cls, path: str, filename: Optional[str] = None) -> 'Payload':
5968
return cls(path=path, filename=filename)
6069

6170
@classmethod
62-
def from_json(cls, json: Dict[str, Any]) -> 'Payload':
63-
return cls(data=json.dumps(json))
71+
def from_json(cls, data: Dict[str, Any]) -> 'Payload':
72+
return cls.from_string(json.dumps(data))

appwrite/services/account.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def update_email(self, email, password):
5757
}, api_params)
5858

5959
def list_identities(self, queries = None):
60-
"""List Identities"""
60+
"""List identities"""
6161
api_path = '/account/identities'
6262
api_params = {}
6363

@@ -116,7 +116,7 @@ def update_mfa(self, mfa):
116116
}, api_params)
117117

118118
def create_mfa_authenticator(self, type):
119-
"""Create Authenticator"""
119+
"""Create authenticator"""
120120
api_path = '/account/mfa/authenticators/{type}'
121121
api_params = {}
122122
if type is None:
@@ -130,7 +130,7 @@ def create_mfa_authenticator(self, type):
130130
}, api_params)
131131

132132
def update_mfa_authenticator(self, type, otp):
133-
"""Verify Authenticator"""
133+
"""Verify authenticator"""
134134
api_path = '/account/mfa/authenticators/{type}'
135135
api_params = {}
136136
if type is None:
@@ -148,7 +148,7 @@ def update_mfa_authenticator(self, type, otp):
148148
}, api_params)
149149

150150
def delete_mfa_authenticator(self, type):
151-
"""Delete Authenticator"""
151+
"""Delete authenticator"""
152152
api_path = '/account/mfa/authenticators/{type}'
153153
api_params = {}
154154
if type is None:
@@ -162,7 +162,7 @@ def delete_mfa_authenticator(self, type):
162162
}, api_params)
163163

164164
def create_mfa_challenge(self, factor):
165-
"""Create MFA Challenge"""
165+
"""Create MFA challenge"""
166166
api_path = '/account/mfa/challenge'
167167
api_params = {}
168168
if factor is None:
@@ -176,7 +176,7 @@ def create_mfa_challenge(self, factor):
176176
}, api_params)
177177

178178
def update_mfa_challenge(self, challenge_id, otp):
179-
"""Create MFA Challenge (confirmation)"""
179+
"""Create MFA challenge (confirmation)"""
180180
api_path = '/account/mfa/challenge'
181181
api_params = {}
182182
if challenge_id is None:
@@ -194,7 +194,7 @@ def update_mfa_challenge(self, challenge_id, otp):
194194
}, api_params)
195195

196196
def list_mfa_factors(self):
197-
"""List Factors"""
197+
"""List factors"""
198198
api_path = '/account/mfa/factors'
199199
api_params = {}
200200

@@ -203,7 +203,7 @@ def list_mfa_factors(self):
203203
}, api_params)
204204

205205
def get_mfa_recovery_codes(self):
206-
"""Get MFA Recovery Codes"""
206+
"""Get MFA recovery codes"""
207207
api_path = '/account/mfa/recovery-codes'
208208
api_params = {}
209209

@@ -212,7 +212,7 @@ def get_mfa_recovery_codes(self):
212212
}, api_params)
213213

214214
def create_mfa_recovery_codes(self):
215-
"""Create MFA Recovery Codes"""
215+
"""Create MFA recovery codes"""
216216
api_path = '/account/mfa/recovery-codes'
217217
api_params = {}
218218

@@ -221,7 +221,7 @@ def create_mfa_recovery_codes(self):
221221
}, api_params)
222222

223223
def update_mfa_recovery_codes(self):
224-
"""Regenerate MFA Recovery Codes"""
224+
"""Regenerate MFA recovery codes"""
225225
api_path = '/account/mfa/recovery-codes'
226226
api_params = {}
227227

appwrite/services/locale.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get(self):
1616
}, api_params)
1717

1818
def list_codes(self):
19-
"""List Locale Codes"""
19+
"""List locale codes"""
2020
api_path = '/locale/codes'
2121
api_params = {}
2222

appwrite/services/storage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def update_file(self, bucket_id, file_id, name = None, permissions = None):
180180
}, api_params)
181181

182182
def delete_file(self, bucket_id, file_id):
183-
"""Delete File"""
183+
"""Delete file"""
184184
api_path = '/storage/buckets/{bucketId}/files/{fileId}'
185185
api_params = {}
186186
if bucket_id is None:

appwrite/services/users.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def create_bcrypt_user(self, user_id, email, password, name = None):
8383
}, api_params)
8484

8585
def list_identities(self, queries = None, search = None):
86-
"""List Identities"""
86+
"""List identities"""
8787
api_path = '/users/identities'
8888
api_params = {}
8989

@@ -384,7 +384,7 @@ def update_mfa(self, user_id, mfa):
384384
}, api_params)
385385

386386
def delete_mfa_authenticator(self, user_id, type):
387-
"""Delete Authenticator"""
387+
"""Delete authenticator"""
388388
api_path = '/users/{userId}/mfa/authenticators/{type}'
389389
api_params = {}
390390
if user_id is None:
@@ -402,7 +402,7 @@ def delete_mfa_authenticator(self, user_id, type):
402402
}, api_params)
403403

404404
def list_mfa_factors(self, user_id):
405-
"""List Factors"""
405+
"""List factors"""
406406
api_path = '/users/{userId}/mfa/factors'
407407
api_params = {}
408408
if user_id is None:
@@ -416,7 +416,7 @@ def list_mfa_factors(self, user_id):
416416
}, api_params)
417417

418418
def get_mfa_recovery_codes(self, user_id):
419-
"""Get MFA Recovery Codes"""
419+
"""Get MFA recovery codes"""
420420
api_path = '/users/{userId}/mfa/recovery-codes'
421421
api_params = {}
422422
if user_id is None:
@@ -430,7 +430,7 @@ def get_mfa_recovery_codes(self, user_id):
430430
}, api_params)
431431

432432
def update_mfa_recovery_codes(self, user_id):
433-
"""Regenerate MFA Recovery Codes"""
433+
"""Regenerate MFA recovery codes"""
434434
api_path = '/users/{userId}/mfa/recovery-codes'
435435
api_params = {}
436436
if user_id is None:
@@ -444,7 +444,7 @@ def update_mfa_recovery_codes(self, user_id):
444444
}, api_params)
445445

446446
def create_mfa_recovery_codes(self, user_id):
447-
"""Create MFA Recovery Codes"""
447+
"""Create MFA recovery codes"""
448448
api_path = '/users/{userId}/mfa/recovery-codes'
449449
api_params = {}
450450
if user_id is None:
@@ -622,7 +622,7 @@ def update_status(self, user_id, status):
622622
}, api_params)
623623

624624
def list_targets(self, user_id, queries = None):
625-
"""List User Targets"""
625+
"""List user targets"""
626626
api_path = '/users/{userId}/targets'
627627
api_params = {}
628628
if user_id is None:
@@ -637,7 +637,7 @@ def list_targets(self, user_id, queries = None):
637637
}, api_params)
638638

639639
def create_target(self, user_id, target_id, provider_type, identifier, provider_id = None, name = None):
640-
"""Create User Target"""
640+
"""Create user target"""
641641
api_path = '/users/{userId}/targets'
642642
api_params = {}
643643
if user_id is None:
@@ -665,7 +665,7 @@ def create_target(self, user_id, target_id, provider_type, identifier, provider_
665665
}, api_params)
666666

667667
def get_target(self, user_id, target_id):
668-
"""Get User Target"""
668+
"""Get user target"""
669669
api_path = '/users/{userId}/targets/{targetId}'
670670
api_params = {}
671671
if user_id is None:
@@ -683,7 +683,7 @@ def get_target(self, user_id, target_id):
683683
}, api_params)
684684

685685
def update_target(self, user_id, target_id, identifier = None, provider_id = None, name = None):
686-
"""Update User target"""
686+
"""Update user target"""
687687
api_path = '/users/{userId}/targets/{targetId}'
688688
api_params = {}
689689
if user_id is None:

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'appwrite/encoders',
1414
'appwrite/enums',
1515
],
16-
version = '7.0.0-rc1',
16+
version = '7.0.0',
1717
license='BSD-3-Clause',
1818
description = 'Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API',
1919
long_description = long_description,
@@ -23,7 +23,7 @@
2323
maintainer = 'Appwrite Team',
2424
maintainer_email = '[email protected]',
2525
url = 'https://appwrite.io/support',
26-
download_url='https://github.com/appwrite/sdk-for-python/archive/7.0.0-rc1.tar.gz',
26+
download_url='https://github.com/appwrite/sdk-for-python/archive/7.0.0.tar.gz',
2727
install_requires=[
2828
'requests',
2929
],

0 commit comments

Comments
 (0)