@@ -79,7 +79,7 @@ def clone(self, **kwargs):
79
79
@contextmanager
80
80
def batch (self , ** kwargs ):
81
81
if self ._server_settings is None :
82
- resp , _ = self .session .request ("GET" , self ._get_endpoint ('root' ))
82
+ resp , _ = self .session .request ("GET" , self .get_endpoint ('root' ))
83
83
self ._server_settings = resp ['settings' ]
84
84
85
85
batch_max_requests = self ._server_settings ['batch_max_requests' ]
@@ -90,7 +90,18 @@ def batch(self, **kwargs):
90
90
batch_session .send ()
91
91
batch_session .reset ()
92
92
93
- def _get_endpoint (self , name , bucket = None , collection = None , id = None ):
93
+ def get_endpoint (self , name , bucket = None , collection = None , id = None ):
94
+ """Return the endpoint with named parameters.
95
+
96
+ Please always use the method as if it was defined like this:
97
+
98
+ get_endpoint(self, name, *,
99
+ bucket=None, collection=None, id=None)
100
+
101
+ Meaning that bucket, collection and id should always be
102
+ named parameters.
103
+
104
+ """
94
105
kwargs = {
95
106
'bucket' : bucket or self ._bucket_name ,
96
107
'collection' : collection or self ._collection_name ,
@@ -151,7 +162,7 @@ def _create_if_not_exists(self, resource, **kwargs):
151
162
# Server Info
152
163
153
164
def server_info (self ):
154
- endpoint = self ._get_endpoint ('root' )
165
+ endpoint = self .get_endpoint ('root' )
155
166
resp , _ = self .session .request ('get' , endpoint )
156
167
return resp
157
168
@@ -166,15 +177,15 @@ def create_bucket(self, bucket=None, data=None, permissions=None,
166
177
permissions = permissions ,
167
178
safe = safe )
168
179
headers = DO_NOT_OVERWRITE if safe else None
169
- endpoint = self ._get_endpoint ('bucket' , bucket )
180
+ endpoint = self .get_endpoint ('bucket' , bucket = bucket )
170
181
resp , _ = self .session .request ('put' , endpoint , data = data ,
171
182
permissions = permissions ,
172
183
headers = headers )
173
184
return resp
174
185
175
186
def update_bucket (self , bucket = None , data = None , permissions = None ,
176
187
safe = True , if_match = None , method = 'put' ):
177
- endpoint = self ._get_endpoint ('bucket' , bucket )
188
+ endpoint = self .get_endpoint ('bucket' , bucket = bucket )
178
189
headers = self ._get_cache_headers (safe , data , if_match )
179
190
resp , _ = self .session .request (method , endpoint , data = data ,
180
191
permissions = permissions ,
@@ -186,33 +197,33 @@ def patch_bucket(self, *args, **kwargs):
186
197
return self .update_bucket (* args , ** kwargs )
187
198
188
199
def get_buckets (self ):
189
- endpoint = self ._get_endpoint ('buckets' )
200
+ endpoint = self .get_endpoint ('buckets' )
190
201
return self ._paginated (endpoint )
191
202
192
203
def get_bucket (self , bucket = None ):
193
- endpoint = self ._get_endpoint ('bucket' , bucket )
204
+ endpoint = self .get_endpoint ('bucket' , bucket = bucket )
194
205
try :
195
206
resp , _ = self .session .request ('get' , endpoint )
196
207
except KintoException as e :
197
208
raise BucketNotFound (bucket or self ._bucket_name , e )
198
209
return resp
199
210
200
211
def delete_bucket (self , bucket = None , safe = True , if_match = None ):
201
- endpoint = self ._get_endpoint ('bucket' , bucket )
212
+ endpoint = self .get_endpoint ('bucket' , bucket = bucket )
202
213
headers = self ._get_cache_headers (safe , if_match = if_match )
203
214
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
204
215
return resp ['data' ]
205
216
206
217
def delete_buckets (self , safe = True , if_match = None ):
207
- endpoint = self ._get_endpoint ('buckets' )
218
+ endpoint = self .get_endpoint ('buckets' )
208
219
headers = self ._get_cache_headers (safe , if_match = if_match )
209
220
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
210
221
return resp ['data' ]
211
222
212
223
# Collections
213
224
214
225
def get_collections (self , bucket = None ):
215
- endpoint = self ._get_endpoint ('collections' , bucket )
226
+ endpoint = self .get_endpoint ('collections' , bucket = bucket )
216
227
return self ._paginated (endpoint )
217
228
218
229
def create_collection (self , collection = None , bucket = None ,
@@ -226,7 +237,9 @@ def create_collection(self, collection=None, bucket=None,
226
237
permissions = permissions ,
227
238
safe = safe )
228
239
headers = DO_NOT_OVERWRITE if safe else None
229
- endpoint = self ._get_endpoint ('collection' , bucket , collection )
240
+ endpoint = self .get_endpoint ('collection' ,
241
+ bucket = bucket ,
242
+ collection = collection )
230
243
try :
231
244
resp , _ = self .session .request ('put' , endpoint , data = data ,
232
245
permissions = permissions ,
@@ -238,12 +251,15 @@ def create_collection(self, collection=None, bucket=None,
238
251
"this collection." )
239
252
e = KintoException (msg , e )
240
253
raise e
254
+
241
255
return resp
242
256
243
257
def update_collection (self , data = None , collection = None , bucket = None ,
244
258
permissions = None , method = 'put' ,
245
259
safe = True , if_match = None ):
246
- endpoint = self ._get_endpoint ('collection' , bucket , collection )
260
+ endpoint = self .get_endpoint ('collection' ,
261
+ bucket = bucket ,
262
+ collection = collection )
247
263
headers = self ._get_cache_headers (safe , data , if_match )
248
264
resp , _ = self .session .request (method , endpoint , data = data ,
249
265
permissions = permissions ,
@@ -255,19 +271,23 @@ def patch_collection(self, *args, **kwargs):
255
271
return self .update_collection (* args , ** kwargs )
256
272
257
273
def get_collection (self , collection = None , bucket = None ):
258
- endpoint = self ._get_endpoint ('collection' , bucket , collection )
274
+ endpoint = self .get_endpoint ('collection' ,
275
+ bucket = bucket ,
276
+ collection = collection )
259
277
resp , _ = self .session .request ('get' , endpoint )
260
278
return resp
261
279
262
280
def delete_collection (self , collection = None , bucket = None ,
263
281
safe = True , if_match = None ):
264
- endpoint = self ._get_endpoint ('collection' , bucket , collection )
282
+ endpoint = self .get_endpoint ('collection' ,
283
+ bucket = bucket ,
284
+ collection = collection )
265
285
headers = self ._get_cache_headers (safe , if_match = if_match )
266
286
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
267
287
return resp ['data' ]
268
288
269
289
def delete_collections (self , bucket = None , safe = True , if_match = None ):
270
- endpoint = self ._get_endpoint ('collections' , bucket )
290
+ endpoint = self .get_endpoint ('collections' , bucket = bucket )
271
291
headers = self ._get_cache_headers (safe , if_match = if_match )
272
292
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
273
293
return resp ['data' ]
@@ -276,12 +296,15 @@ def delete_collections(self, bucket=None, safe=True, if_match=None):
276
296
277
297
def get_records (self , collection = None , bucket = None , ** kwargs ):
278
298
"""Returns all the records"""
279
- # XXX Add filter and sorting.
280
- endpoint = self ._get_endpoint ('records' , bucket , collection )
299
+ endpoint = self .get_endpoint ('records' ,
300
+ bucket = bucket ,
301
+ collection = collection )
281
302
return self ._paginated (endpoint , ** kwargs )
282
303
283
304
def get_record (self , id , collection = None , bucket = None ):
284
- endpoint = self ._get_endpoint ('record' , bucket , collection , id )
305
+ endpoint = self .get_endpoint ('record' , id = id ,
306
+ bucket = bucket ,
307
+ collection = collection )
285
308
resp , _ = self .session .request ('get' , endpoint )
286
309
return resp
287
310
@@ -299,7 +322,9 @@ def create_record(self, data, id=None, collection=None, permissions=None,
299
322
# Make sure that no record already exists with this id.
300
323
headers = DO_NOT_OVERWRITE if safe else None
301
324
302
- endpoint = self ._get_endpoint ('record' , bucket , collection , id )
325
+ endpoint = self .get_endpoint ('record' , id = id ,
326
+ bucket = bucket ,
327
+ collection = collection )
303
328
try :
304
329
resp , _ = self .session .request ('put' , endpoint , data = data ,
305
330
permissions = permissions ,
@@ -320,7 +345,9 @@ def update_record(self, data, id=None, collection=None, permissions=None,
320
345
id = id or data .get ('id' )
321
346
if id is None :
322
347
raise KeyError ('Unable to update a record, need an id.' )
323
- endpoint = self ._get_endpoint ('record' , bucket , collection , id )
348
+ endpoint = self .get_endpoint ('record' , id = id ,
349
+ bucket = bucket ,
350
+ collection = collection )
324
351
headers = self ._get_cache_headers (safe , data , if_match )
325
352
resp , _ = self .session .request (method , endpoint , data = data ,
326
353
headers = headers ,
@@ -333,23 +360,27 @@ def patch_record(self, *args, **kwargs):
333
360
334
361
def delete_record (self , id , collection = None , bucket = None ,
335
362
safe = True , if_match = None ):
336
- endpoint = self ._get_endpoint ('record' , bucket , collection , id )
363
+ endpoint = self .get_endpoint ('record' , id = id ,
364
+ bucket = bucket ,
365
+ collection = collection )
337
366
headers = self ._get_cache_headers (safe , if_match = if_match )
338
367
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
339
368
return resp ['data' ]
340
369
341
370
def delete_records (self , collection = None , bucket = None ,
342
371
safe = True , if_match = None ):
343
- endpoint = self ._get_endpoint ('records' , bucket , collection )
372
+ endpoint = self .get_endpoint ('records' ,
373
+ bucket = bucket ,
374
+ collection = collection )
344
375
headers = self ._get_cache_headers (safe , if_match = if_match )
345
376
resp , _ = self .session .request ('delete' , endpoint , headers = headers )
346
377
return resp ['data' ]
347
378
348
379
def __repr__ (self ):
349
- endpoint = self ._get_endpoint (
380
+ endpoint = self .get_endpoint (
350
381
'collection' ,
351
- self ._bucket_name ,
352
- self ._collection_name
382
+ bucket = self ._bucket_name ,
383
+ collection = self ._collection_name
353
384
)
354
385
absolute_endpoint = utils .urljoin (self .session .server_url , endpoint )
355
386
return "<KintoClient %s>" % absolute_endpoint
0 commit comments