swift 2.23.2__py3-none-any.whl → 2.35.0__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.
Files changed (208) hide show
  1. swift/__init__.py +29 -50
  2. swift/account/auditor.py +21 -118
  3. swift/account/backend.py +33 -28
  4. swift/account/reaper.py +37 -28
  5. swift/account/replicator.py +22 -0
  6. swift/account/server.py +60 -26
  7. swift/account/utils.py +28 -11
  8. swift-2.23.2.data/scripts/swift-account-audit → swift/cli/account_audit.py +23 -13
  9. swift-2.23.2.data/scripts/swift-config → swift/cli/config.py +2 -2
  10. swift/cli/container_deleter.py +5 -11
  11. swift-2.23.2.data/scripts/swift-dispersion-populate → swift/cli/dispersion_populate.py +8 -7
  12. swift/cli/dispersion_report.py +10 -9
  13. swift-2.23.2.data/scripts/swift-drive-audit → swift/cli/drive_audit.py +63 -21
  14. swift/cli/form_signature.py +3 -7
  15. swift-2.23.2.data/scripts/swift-get-nodes → swift/cli/get_nodes.py +8 -2
  16. swift/cli/info.py +183 -29
  17. swift/cli/manage_shard_ranges.py +708 -37
  18. swift-2.23.2.data/scripts/swift-oldies → swift/cli/oldies.py +25 -14
  19. swift-2.23.2.data/scripts/swift-orphans → swift/cli/orphans.py +7 -3
  20. swift/cli/recon.py +196 -67
  21. swift-2.23.2.data/scripts/swift-recon-cron → swift/cli/recon_cron.py +17 -20
  22. swift-2.23.2.data/scripts/swift-reconciler-enqueue → swift/cli/reconciler_enqueue.py +2 -3
  23. swift/cli/relinker.py +807 -126
  24. swift/cli/reload.py +135 -0
  25. swift/cli/ringbuilder.py +217 -20
  26. swift/cli/ringcomposer.py +0 -1
  27. swift/cli/shard-info.py +4 -3
  28. swift/common/base_storage_server.py +9 -20
  29. swift/common/bufferedhttp.py +48 -74
  30. swift/common/constraints.py +20 -15
  31. swift/common/container_sync_realms.py +9 -11
  32. swift/common/daemon.py +25 -8
  33. swift/common/db.py +198 -127
  34. swift/common/db_auditor.py +168 -0
  35. swift/common/db_replicator.py +95 -55
  36. swift/common/digest.py +141 -0
  37. swift/common/direct_client.py +144 -33
  38. swift/common/error_limiter.py +93 -0
  39. swift/common/exceptions.py +25 -1
  40. swift/common/header_key_dict.py +2 -9
  41. swift/common/http_protocol.py +373 -0
  42. swift/common/internal_client.py +129 -59
  43. swift/common/linkat.py +3 -4
  44. swift/common/manager.py +284 -67
  45. swift/common/memcached.py +396 -147
  46. swift/common/middleware/__init__.py +4 -0
  47. swift/common/middleware/account_quotas.py +211 -46
  48. swift/common/middleware/acl.py +3 -8
  49. swift/common/middleware/backend_ratelimit.py +230 -0
  50. swift/common/middleware/bulk.py +22 -34
  51. swift/common/middleware/catch_errors.py +1 -3
  52. swift/common/middleware/cname_lookup.py +6 -11
  53. swift/common/middleware/container_quotas.py +1 -1
  54. swift/common/middleware/container_sync.py +39 -17
  55. swift/common/middleware/copy.py +12 -0
  56. swift/common/middleware/crossdomain.py +22 -9
  57. swift/common/middleware/crypto/__init__.py +2 -1
  58. swift/common/middleware/crypto/crypto_utils.py +11 -15
  59. swift/common/middleware/crypto/decrypter.py +28 -11
  60. swift/common/middleware/crypto/encrypter.py +12 -17
  61. swift/common/middleware/crypto/keymaster.py +8 -15
  62. swift/common/middleware/crypto/kms_keymaster.py +2 -1
  63. swift/common/middleware/dlo.py +15 -11
  64. swift/common/middleware/domain_remap.py +5 -4
  65. swift/common/middleware/etag_quoter.py +128 -0
  66. swift/common/middleware/formpost.py +73 -70
  67. swift/common/middleware/gatekeeper.py +8 -1
  68. swift/common/middleware/keystoneauth.py +33 -3
  69. swift/common/middleware/list_endpoints.py +4 -4
  70. swift/common/middleware/listing_formats.py +85 -49
  71. swift/common/middleware/memcache.py +4 -81
  72. swift/common/middleware/name_check.py +3 -2
  73. swift/common/middleware/proxy_logging.py +160 -92
  74. swift/common/middleware/ratelimit.py +17 -10
  75. swift/common/middleware/read_only.py +6 -4
  76. swift/common/middleware/recon.py +59 -22
  77. swift/common/middleware/s3api/acl_handlers.py +25 -3
  78. swift/common/middleware/s3api/acl_utils.py +6 -1
  79. swift/common/middleware/s3api/controllers/__init__.py +6 -0
  80. swift/common/middleware/s3api/controllers/acl.py +3 -2
  81. swift/common/middleware/s3api/controllers/bucket.py +242 -137
  82. swift/common/middleware/s3api/controllers/logging.py +2 -2
  83. swift/common/middleware/s3api/controllers/multi_delete.py +43 -20
  84. swift/common/middleware/s3api/controllers/multi_upload.py +219 -133
  85. swift/common/middleware/s3api/controllers/obj.py +112 -8
  86. swift/common/middleware/s3api/controllers/object_lock.py +44 -0
  87. swift/common/middleware/s3api/controllers/s3_acl.py +2 -2
  88. swift/common/middleware/s3api/controllers/tagging.py +57 -0
  89. swift/common/middleware/s3api/controllers/versioning.py +36 -7
  90. swift/common/middleware/s3api/etree.py +22 -9
  91. swift/common/middleware/s3api/exception.py +0 -4
  92. swift/common/middleware/s3api/s3api.py +113 -41
  93. swift/common/middleware/s3api/s3request.py +384 -218
  94. swift/common/middleware/s3api/s3response.py +126 -23
  95. swift/common/middleware/s3api/s3token.py +16 -17
  96. swift/common/middleware/s3api/schema/delete.rng +1 -1
  97. swift/common/middleware/s3api/subresource.py +7 -10
  98. swift/common/middleware/s3api/utils.py +27 -10
  99. swift/common/middleware/slo.py +665 -358
  100. swift/common/middleware/staticweb.py +64 -37
  101. swift/common/middleware/symlink.py +52 -19
  102. swift/common/middleware/tempauth.py +76 -58
  103. swift/common/middleware/tempurl.py +192 -174
  104. swift/common/middleware/versioned_writes/__init__.py +51 -0
  105. swift/common/middleware/{versioned_writes.py → versioned_writes/legacy.py} +27 -26
  106. swift/common/middleware/versioned_writes/object_versioning.py +1482 -0
  107. swift/common/middleware/x_profile/exceptions.py +1 -4
  108. swift/common/middleware/x_profile/html_viewer.py +18 -19
  109. swift/common/middleware/x_profile/profile_model.py +1 -2
  110. swift/common/middleware/xprofile.py +10 -10
  111. swift-2.23.2.data/scripts/swift-container-server → swift/common/recon.py +13 -8
  112. swift/common/registry.py +147 -0
  113. swift/common/request_helpers.py +324 -57
  114. swift/common/ring/builder.py +67 -25
  115. swift/common/ring/composite_builder.py +1 -1
  116. swift/common/ring/ring.py +177 -51
  117. swift/common/ring/utils.py +1 -1
  118. swift/common/splice.py +10 -6
  119. swift/common/statsd_client.py +205 -0
  120. swift/common/storage_policy.py +49 -44
  121. swift/common/swob.py +86 -102
  122. swift/common/{utils.py → utils/__init__.py} +2191 -2762
  123. swift/common/utils/base.py +131 -0
  124. swift/common/utils/config.py +433 -0
  125. swift/common/utils/ipaddrs.py +256 -0
  126. swift/common/utils/libc.py +345 -0
  127. swift/common/utils/logs.py +859 -0
  128. swift/common/utils/timestamp.py +412 -0
  129. swift/common/wsgi.py +555 -536
  130. swift/container/auditor.py +14 -100
  131. swift/container/backend.py +552 -227
  132. swift/container/reconciler.py +126 -37
  133. swift/container/replicator.py +96 -22
  134. swift/container/server.py +397 -176
  135. swift/container/sharder.py +1580 -639
  136. swift/container/sync.py +94 -88
  137. swift/container/updater.py +53 -32
  138. swift/obj/auditor.py +153 -35
  139. swift/obj/diskfile.py +466 -217
  140. swift/obj/expirer.py +406 -124
  141. swift/obj/mem_diskfile.py +7 -4
  142. swift/obj/mem_server.py +1 -0
  143. swift/obj/reconstructor.py +523 -262
  144. swift/obj/replicator.py +249 -188
  145. swift/obj/server.py +213 -122
  146. swift/obj/ssync_receiver.py +145 -85
  147. swift/obj/ssync_sender.py +113 -54
  148. swift/obj/updater.py +653 -139
  149. swift/obj/watchers/__init__.py +0 -0
  150. swift/obj/watchers/dark_data.py +213 -0
  151. swift/proxy/controllers/account.py +11 -11
  152. swift/proxy/controllers/base.py +848 -604
  153. swift/proxy/controllers/container.py +452 -86
  154. swift/proxy/controllers/info.py +3 -2
  155. swift/proxy/controllers/obj.py +1009 -490
  156. swift/proxy/server.py +185 -112
  157. swift-2.35.0.dist-info/AUTHORS +501 -0
  158. swift-2.35.0.dist-info/LICENSE +202 -0
  159. {swift-2.23.2.dist-info → swift-2.35.0.dist-info}/METADATA +52 -61
  160. swift-2.35.0.dist-info/RECORD +201 -0
  161. {swift-2.23.2.dist-info → swift-2.35.0.dist-info}/WHEEL +1 -1
  162. {swift-2.23.2.dist-info → swift-2.35.0.dist-info}/entry_points.txt +43 -0
  163. swift-2.35.0.dist-info/pbr.json +1 -0
  164. swift/locale/de/LC_MESSAGES/swift.po +0 -1216
  165. swift/locale/en_GB/LC_MESSAGES/swift.po +0 -1207
  166. swift/locale/es/LC_MESSAGES/swift.po +0 -1085
  167. swift/locale/fr/LC_MESSAGES/swift.po +0 -909
  168. swift/locale/it/LC_MESSAGES/swift.po +0 -894
  169. swift/locale/ja/LC_MESSAGES/swift.po +0 -965
  170. swift/locale/ko_KR/LC_MESSAGES/swift.po +0 -964
  171. swift/locale/pt_BR/LC_MESSAGES/swift.po +0 -881
  172. swift/locale/ru/LC_MESSAGES/swift.po +0 -891
  173. swift/locale/tr_TR/LC_MESSAGES/swift.po +0 -832
  174. swift/locale/zh_CN/LC_MESSAGES/swift.po +0 -833
  175. swift/locale/zh_TW/LC_MESSAGES/swift.po +0 -838
  176. swift-2.23.2.data/scripts/swift-account-auditor +0 -23
  177. swift-2.23.2.data/scripts/swift-account-info +0 -51
  178. swift-2.23.2.data/scripts/swift-account-reaper +0 -23
  179. swift-2.23.2.data/scripts/swift-account-replicator +0 -34
  180. swift-2.23.2.data/scripts/swift-account-server +0 -23
  181. swift-2.23.2.data/scripts/swift-container-auditor +0 -23
  182. swift-2.23.2.data/scripts/swift-container-info +0 -51
  183. swift-2.23.2.data/scripts/swift-container-reconciler +0 -21
  184. swift-2.23.2.data/scripts/swift-container-replicator +0 -34
  185. swift-2.23.2.data/scripts/swift-container-sharder +0 -33
  186. swift-2.23.2.data/scripts/swift-container-sync +0 -23
  187. swift-2.23.2.data/scripts/swift-container-updater +0 -23
  188. swift-2.23.2.data/scripts/swift-dispersion-report +0 -24
  189. swift-2.23.2.data/scripts/swift-form-signature +0 -20
  190. swift-2.23.2.data/scripts/swift-init +0 -119
  191. swift-2.23.2.data/scripts/swift-object-auditor +0 -29
  192. swift-2.23.2.data/scripts/swift-object-expirer +0 -33
  193. swift-2.23.2.data/scripts/swift-object-info +0 -60
  194. swift-2.23.2.data/scripts/swift-object-reconstructor +0 -33
  195. swift-2.23.2.data/scripts/swift-object-relinker +0 -41
  196. swift-2.23.2.data/scripts/swift-object-replicator +0 -37
  197. swift-2.23.2.data/scripts/swift-object-server +0 -27
  198. swift-2.23.2.data/scripts/swift-object-updater +0 -23
  199. swift-2.23.2.data/scripts/swift-proxy-server +0 -23
  200. swift-2.23.2.data/scripts/swift-recon +0 -24
  201. swift-2.23.2.data/scripts/swift-ring-builder +0 -24
  202. swift-2.23.2.data/scripts/swift-ring-builder-analyzer +0 -22
  203. swift-2.23.2.data/scripts/swift-ring-composer +0 -22
  204. swift-2.23.2.dist-info/DESCRIPTION.rst +0 -166
  205. swift-2.23.2.dist-info/RECORD +0 -220
  206. swift-2.23.2.dist-info/metadata.json +0 -1
  207. swift-2.23.2.dist-info/pbr.json +0 -1
  208. {swift-2.23.2.dist-info → swift-2.35.0.dist-info}/top_level.txt +0 -0
@@ -13,29 +13,26 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from eventlet import sleep, Timeout
17
- from eventlet.green import httplib, socket
16
+ from eventlet import sleep, Timeout, spawn
17
+ from eventlet.green import socket
18
+ from eventlet.green.http import client as http_client
19
+ from eventlet.green.urllib import request as urllib_request
18
20
  import json
19
- import six
20
- from six.moves import range
21
- from six.moves import urllib
21
+ import urllib
22
22
  import struct
23
- from sys import exc_info, exit
23
+ from sys import exit
24
24
  import zlib
25
25
  from time import gmtime, strftime, time
26
26
  from zlib import compressobj
27
27
 
28
28
  from swift.common.exceptions import ClientException
29
29
  from swift.common.http import (HTTP_NOT_FOUND, HTTP_MULTIPLE_CHOICES,
30
- is_server_error)
30
+ is_client_error, is_server_error)
31
+ from swift.common.middleware.gatekeeper import GatekeeperMiddleware
32
+ from swift.common.request_helpers import USE_REPLICATION_NETWORK_HEADER
31
33
  from swift.common.swob import Request, bytes_to_wsgi
32
- from swift.common.utils import quote, closing_if_possible
33
- from swift.common.wsgi import loadapp, pipeline_property
34
-
35
- if six.PY3:
36
- from eventlet.green.urllib import request as urllib2
37
- else:
38
- from eventlet.green import urllib2
34
+ from swift.common.utils import quote, close_if_possible, drain_and_close
35
+ from swift.common.wsgi import loadapp
39
36
 
40
37
 
41
38
  class UnexpectedResponse(Exception):
@@ -125,8 +122,6 @@ class CompressingFileReader(object):
125
122
  return chunk
126
123
  raise StopIteration
127
124
 
128
- next = __next__
129
-
130
125
  def seek(self, offset, whence=0):
131
126
  if not (offset == 0 and whence == 0):
132
127
  raise NotImplementedError('Seek implemented on offset 0 only')
@@ -143,22 +138,48 @@ class InternalClient(object):
143
138
  :param user_agent: User agent to be sent to requests to Swift.
144
139
  :param request_tries: Number of tries before InternalClient.make_request()
145
140
  gives up.
141
+ :param use_replication_network: Force the client to use the replication
142
+ network over the cluster.
143
+ :param global_conf: a dict of options to update the loaded proxy config.
144
+ Options in ``global_conf`` will override those in ``conf_path`` except
145
+ where the ``conf_path`` option is preceded by ``set``.
146
+ :param app: Optionally provide a WSGI app for the internal client to use.
146
147
  """
147
148
 
148
149
  def __init__(self, conf_path, user_agent, request_tries,
149
- allow_modify_pipeline=False):
150
+ use_replication_network=False, global_conf=None, app=None,
151
+ **kwargs):
150
152
  if request_tries < 1:
151
153
  raise ValueError('request_tries must be positive')
152
- self.app = loadapp(conf_path,
153
- allow_modify_pipeline=allow_modify_pipeline)
154
- self.user_agent = user_agent
154
+ # Internal clients don't use the gatekeeper and the pipeline remains
155
+ # static so we never allow anything to modify the proxy pipeline.
156
+ if kwargs.get('allow_modify_pipeline'):
157
+ raise ValueError("'allow_modify_pipeline' is no longer supported")
158
+ self.app = app or loadapp(conf_path, global_conf=global_conf,
159
+ allow_modify_pipeline=False,)
160
+ self.check_gatekeeper_not_loaded(self.app)
161
+ self.user_agent = \
162
+ self.app._pipeline_final_app.backend_user_agent = user_agent
155
163
  self.request_tries = request_tries
156
-
157
- get_object_ring = pipeline_property('get_object_ring')
158
- container_ring = pipeline_property('container_ring')
159
- account_ring = pipeline_property('account_ring')
160
- auto_create_account_prefix = pipeline_property(
161
- 'auto_create_account_prefix', default='.')
164
+ self.use_replication_network = use_replication_network
165
+ self.get_object_ring = self.app._pipeline_final_app.get_object_ring
166
+ self.container_ring = self.app._pipeline_final_app.container_ring
167
+ self.account_ring = self.app._pipeline_final_app.account_ring
168
+ self.auto_create_account_prefix = \
169
+ self.app._pipeline_final_app.auto_create_account_prefix
170
+
171
+ @staticmethod
172
+ def check_gatekeeper_not_loaded(app):
173
+ # the Gatekeeper middleware would prevent an InternalClient passing
174
+ # X-Backend-* headers to the proxy app, so ensure it's not present
175
+ try:
176
+ for app in app._pipeline:
177
+ if isinstance(app, GatekeeperMiddleware):
178
+ raise ValueError(
179
+ "Gatekeeper middleware is not allowed in the "
180
+ "InternalClient proxy pipeline")
181
+ except AttributeError:
182
+ pass
162
183
 
163
184
  def make_request(
164
185
  self, method, path, headers, acceptable_statuses, body_file=None,
@@ -184,8 +205,12 @@ class InternalClient(object):
184
205
 
185
206
  headers = dict(headers)
186
207
  headers['user-agent'] = self.user_agent
208
+ headers.setdefault('x-backend-allow-reserved-names', 'true')
209
+ if self.use_replication_network:
210
+ headers.setdefault(USE_REPLICATION_NETWORK_HEADER, 'true')
211
+
187
212
  for attempt in range(self.request_tries):
188
- resp = exc_type = exc_value = exc_traceback = None
213
+ resp = err = None
189
214
  req = Request.blank(
190
215
  path, environ={'REQUEST_METHOD': method}, headers=headers)
191
216
  if body_file is not None:
@@ -195,9 +220,10 @@ class InternalClient(object):
195
220
  if params:
196
221
  req.params = params
197
222
  try:
198
- resp = req.get_response(self.app)
199
- except (Exception, Timeout):
200
- exc_type, exc_value, exc_traceback = exc_info()
223
+ # execute in a separate greenthread to not polute corolocals
224
+ resp = spawn(req.get_response, self.app).wait()
225
+ except (Exception, Timeout) as e:
226
+ err = e
201
227
  else:
202
228
  if resp.status_int in acceptable_statuses or \
203
229
  resp.status_int // 100 in acceptable_statuses:
@@ -208,13 +234,13 @@ class InternalClient(object):
208
234
  # sleep only between tries, not after each one
209
235
  if attempt < self.request_tries - 1:
210
236
  if resp:
211
- # always close any resp.app_iter before we discard it
212
- with closing_if_possible(resp.app_iter):
213
- # for non 2XX requests it's safe and useful to drain
214
- # the response body so we log the correct status code
215
- if resp.status_int // 100 != 2:
216
- for iter_body in resp.app_iter:
217
- pass
237
+ # for non 2XX requests it's safe and useful to drain
238
+ # the response body so we log the correct status code
239
+ if resp.status_int // 100 != 2:
240
+ drain_and_close(resp)
241
+ else:
242
+ # Just close; the 499 is appropriate
243
+ close_if_possible(resp.app_iter)
218
244
  sleep(2 ** (attempt + 1))
219
245
  if resp:
220
246
  msg = 'Unexpected response: %s' % resp.status
@@ -223,9 +249,14 @@ class InternalClient(object):
223
249
  # non 2XX responses
224
250
  msg += ' (%s)' % resp.body
225
251
  raise UnexpectedResponse(msg, resp)
226
- if exc_type:
227
- # To make pep8 tool happy, in place of raise t, v, tb:
228
- six.reraise(exc_type, exc_value, exc_traceback)
252
+ if err:
253
+ raise err
254
+
255
+ def handle_request(self, *args, **kwargs):
256
+ resp = self.make_request(*args, **kwargs)
257
+ # Drain the response body to prevent unexpected disconnect
258
+ # in proxy-server
259
+ drain_and_close(resp)
229
260
 
230
261
  def _get_metadata(
231
262
  self, path, metadata_prefix='', acceptable_statuses=(2,),
@@ -356,7 +387,7 @@ class InternalClient(object):
356
387
  headers[k] = v
357
388
  else:
358
389
  headers['%s%s' % (metadata_prefix, k)] = v
359
- self.make_request('POST', path, headers, acceptable_statuses)
390
+ self.handle_request('POST', path, headers, acceptable_statuses)
360
391
 
361
392
  # account methods
362
393
 
@@ -384,6 +415,34 @@ class InternalClient(object):
384
415
  return self._iter_items(path, marker, end_marker, prefix,
385
416
  acceptable_statuses)
386
417
 
418
+ def create_account(self, account):
419
+ """
420
+ Creates an account.
421
+
422
+ :param account: Account to create.
423
+ :raises UnexpectedResponse: Exception raised when requests fail
424
+ to get a response with an acceptable status
425
+ :raises Exception: Exception is raised when code fails in an
426
+ unexpected way.
427
+ """
428
+ path = self.make_path(account)
429
+ self.handle_request('PUT', path, {}, (201, 202))
430
+
431
+ def delete_account(self, account, acceptable_statuses=(2, HTTP_NOT_FOUND)):
432
+ """
433
+ Deletes an account.
434
+
435
+ :param account: Account to delete.
436
+ :param acceptable_statuses: List of status for valid responses,
437
+ defaults to (2, HTTP_NOT_FOUND).
438
+ :raises UnexpectedResponse: Exception raised when requests fail
439
+ to get a response with an acceptable status
440
+ :raises Exception: Exception is raised when code fails in an
441
+ unexpected way.
442
+ """
443
+ path = self.make_path(account)
444
+ self.handle_request('DELETE', path, {}, acceptable_statuses)
445
+
387
446
  def get_account_info(
388
447
  self, account, acceptable_statuses=(2, HTTP_NOT_FOUND)):
389
448
  """
@@ -496,10 +555,11 @@ class InternalClient(object):
496
555
 
497
556
  headers = headers or {}
498
557
  path = self.make_path(account, container)
499
- self.make_request('PUT', path, headers, acceptable_statuses)
558
+ self.handle_request('PUT', path, headers, acceptable_statuses)
500
559
 
501
560
  def delete_container(
502
- self, account, container, acceptable_statuses=(2, HTTP_NOT_FOUND)):
561
+ self, account, container, headers=None,
562
+ acceptable_statuses=(2, HTTP_NOT_FOUND)):
503
563
  """
504
564
  Deletes a container.
505
565
 
@@ -514,8 +574,9 @@ class InternalClient(object):
514
574
  unexpected way.
515
575
  """
516
576
 
577
+ headers = headers or {}
517
578
  path = self.make_path(account, container)
518
- self.make_request('DELETE', path, {}, acceptable_statuses)
579
+ self.handle_request('DELETE', path, headers, acceptable_statuses)
519
580
 
520
581
  def get_container_metadata(
521
582
  self, account, container, metadata_prefix='',
@@ -618,7 +679,8 @@ class InternalClient(object):
618
679
  """
619
680
 
620
681
  path = self.make_path(account, container, obj)
621
- self.make_request('DELETE', path, (headers or {}), acceptable_statuses)
682
+ self.handle_request('DELETE', path, (headers or {}),
683
+ acceptable_statuses)
622
684
 
623
685
  def get_object_metadata(
624
686
  self, account, container, obj, metadata_prefix='',
@@ -647,7 +709,7 @@ class InternalClient(object):
647
709
  return self._get_metadata(path, metadata_prefix, acceptable_statuses,
648
710
  headers=headers, params=params)
649
711
 
650
- def get_object(self, account, container, obj, headers,
712
+ def get_object(self, account, container, obj, headers=None,
651
713
  acceptable_statuses=(2,), params=None):
652
714
  """
653
715
  Gets an object.
@@ -749,13 +811,17 @@ class InternalClient(object):
749
811
  path, metadata, metadata_prefix, acceptable_statuses)
750
812
 
751
813
  def upload_object(
752
- self, fobj, account, container, obj, headers=None):
814
+ self, fobj, account, container, obj, headers=None,
815
+ acceptable_statuses=(2,), params=None):
753
816
  """
754
817
  :param fobj: File object to read object's content from.
755
818
  :param account: The object's account.
756
819
  :param container: The object's container.
757
820
  :param obj: The object.
758
821
  :param headers: Headers to send with request, defaults to empty dict.
822
+ :param acceptable_statuses: List of acceptable statuses for request.
823
+ :param params: A dict of params to be set in request query string,
824
+ defaults to None.
759
825
 
760
826
  :raises UnexpectedResponse: Exception raised when requests fail
761
827
  to get a response with an acceptable status
@@ -767,16 +833,17 @@ class InternalClient(object):
767
833
  if 'Content-Length' not in headers:
768
834
  headers['Transfer-Encoding'] = 'chunked'
769
835
  path = self.make_path(account, container, obj)
770
- self.make_request('PUT', path, headers, (2,), fobj)
836
+ self.handle_request('PUT', path, headers, acceptable_statuses, fobj,
837
+ params=params)
771
838
 
772
839
 
773
840
  def get_auth(url, user, key, auth_version='1.0', **kwargs):
774
841
  if auth_version != '1.0':
775
842
  exit('ERROR: swiftclient missing, only auth v1.0 supported')
776
- req = urllib2.Request(url)
843
+ req = urllib_request.Request(url)
777
844
  req.add_header('X-Auth-User', user)
778
845
  req.add_header('X-Auth-Key', key)
779
- conn = urllib2.urlopen(req)
846
+ conn = urllib_request.urlopen(req)
780
847
  headers = conn.info()
781
848
  return (
782
849
  headers.getheader('X-Storage-Url'),
@@ -839,12 +906,12 @@ class SimpleClient(object):
839
906
 
840
907
  url += '?' + '&'.join(params)
841
908
 
842
- req = urllib2.Request(url, headers=headers, data=contents)
909
+ req = urllib_request.Request(url, headers=headers, data=contents)
843
910
  if proxy:
844
911
  proxy = urllib.parse.urlparse(proxy)
845
912
  req.set_proxy(proxy.netloc, proxy.scheme)
846
913
  req.get_method = lambda: method
847
- conn = urllib2.urlopen(req, timeout=timeout)
914
+ conn = urllib_request.urlopen(req, timeout=timeout)
848
915
  body = conn.read()
849
916
  info = conn.info()
850
917
  try:
@@ -886,14 +953,17 @@ class SimpleClient(object):
886
953
  self.attempts += 1
887
954
  try:
888
955
  return self.base_request(method, **kwargs)
889
- except (socket.error, httplib.HTTPException, urllib2.URLError) \
890
- as err:
956
+ except urllib_request.HTTPError as err:
957
+ if is_client_error(err.getcode() or 500):
958
+ raise ClientException('Client error',
959
+ http_status=err.getcode())
960
+ elif self.attempts > retries:
961
+ raise ClientException('Raise too many retries',
962
+ http_status=err.getcode())
963
+ except (socket.error, http_client.HTTPException,
964
+ urllib_request.URLError):
891
965
  if self.attempts > retries:
892
- if isinstance(err, urllib2.HTTPError):
893
- raise ClientException('Raise too many retries',
894
- http_status=err.getcode())
895
- else:
896
- raise
966
+ raise
897
967
  sleep(backoff)
898
968
  backoff = min(backoff * 2, self.max_backoff)
899
969
 
swift/common/linkat.py CHANGED
@@ -17,8 +17,6 @@ import os
17
17
  import ctypes
18
18
  from ctypes.util import find_library
19
19
 
20
- import six
21
-
22
20
  __all__ = ['linkat']
23
21
 
24
22
 
@@ -72,12 +70,13 @@ class Linkat(object):
72
70
  if not isinstance(olddirfd, int) or not isinstance(newdirfd, int):
73
71
  raise TypeError("fd must be an integer.")
74
72
 
75
- if isinstance(oldpath, six.text_type):
73
+ if isinstance(oldpath, str):
76
74
  oldpath = oldpath.encode('utf8')
77
- if isinstance(newpath, six.text_type):
75
+ if isinstance(newpath, str):
78
76
  newpath = newpath.encode('utf8')
79
77
 
80
78
  return self._c_linkat(olddirfd, oldpath, newdirfd, newpath, flags)
81
79
 
80
+
82
81
  linkat = Linkat()
83
82
  del Linkat