pulp_2to3_migration_client 0.12.0.dev1623642407 → 0.12.0.dev1624592835

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +4 -4
  4. data/build/lib/pulpcore/__init__.py +2 -0
  5. data/build/lib/pulpcore/client/__init__.py +2 -0
  6. data/build/lib/pulpcore/client/pulp_2to3_migration/__init__.py +43 -0
  7. data/build/lib/pulpcore/client/pulp_2to3_migration/api/__init__.py +8 -0
  8. data/build/lib/pulpcore/client/pulp_2to3_migration/api/migration_plans_api.py +761 -0
  9. data/build/lib/pulpcore/client/pulp_2to3_migration/api/pulp2_content_api.py +350 -0
  10. data/build/lib/pulpcore/client/pulp_2to3_migration/api/pulp2_repositories_api.py +313 -0
  11. data/build/lib/pulpcore/client/pulp_2to3_migration/api_client.py +667 -0
  12. data/build/lib/pulpcore/client/pulp_2to3_migration/configuration.py +427 -0
  13. data/build/lib/pulpcore/client/pulp_2to3_migration/exceptions.py +121 -0
  14. data/build/lib/pulpcore/client/pulp_2to3_migration/models/__init__.py +26 -0
  15. data/build/lib/pulpcore/client/pulp_2to3_migration/models/async_operation_response.py +124 -0
  16. data/build/lib/pulpcore/client/pulp_2to3_migration/models/migration_plan_run.py +179 -0
  17. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_migration_plan_response_list.py +197 -0
  18. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_content_response_list.py +197 -0
  19. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_repository_response_list.py +197 -0
  20. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan.py +124 -0
  21. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan_response.py +178 -0
  22. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_content_response.py +338 -0
  23. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_repository_response.py +416 -0
  24. data/build/lib/pulpcore/client/pulp_2to3_migration/rest.py +292 -0
  25. data/dist/pulp_2to3_migration-client-0.12.0.dev1624592827.tar.gz +0 -0
  26. data/dist/pulp_2to3_migration_client-0.12.0.dev1624592827-py3-none-any.whl +0 -0
  27. data/lib/pulp_2to3_migration_client.rb +1 -1
  28. data/lib/pulp_2to3_migration_client/api/migration_plans_api.rb +1 -1
  29. data/lib/pulp_2to3_migration_client/api/pulp2_content_api.rb +1 -1
  30. data/lib/pulp_2to3_migration_client/api/pulp2_repositories_api.rb +1 -1
  31. data/lib/pulp_2to3_migration_client/api_client.rb +12 -8
  32. data/lib/pulp_2to3_migration_client/api_error.rb +1 -1
  33. data/lib/pulp_2to3_migration_client/configuration.rb +8 -1
  34. data/lib/pulp_2to3_migration_client/models/async_operation_response.rb +1 -1
  35. data/lib/pulp_2to3_migration_client/models/migration_plan_run.rb +1 -1
  36. data/lib/pulp_2to3_migration_client/models/paginatedpulp2to3_migration_migration_plan_response_list.rb +1 -1
  37. data/lib/pulp_2to3_migration_client/models/paginatedpulp2to3_migration_pulp2_content_response_list.rb +1 -1
  38. data/lib/pulp_2to3_migration_client/models/paginatedpulp2to3_migration_pulp2_repository_response_list.rb +1 -1
  39. data/lib/pulp_2to3_migration_client/models/pulp2to3_migration_migration_plan.rb +1 -1
  40. data/lib/pulp_2to3_migration_client/models/pulp2to3_migration_migration_plan_response.rb +1 -1
  41. data/lib/pulp_2to3_migration_client/models/pulp2to3_migration_pulp2_content_response.rb +1 -1
  42. data/lib/pulp_2to3_migration_client/models/pulp2to3_migration_pulp2_repository_response.rb +1 -1
  43. data/lib/pulp_2to3_migration_client/version.rb +2 -2
  44. data/pulp_2to3_migration_client.egg-info/PKG-INFO +15 -0
  45. data/pulp_2to3_migration_client.egg-info/SOURCES.txt +41 -0
  46. data/pulp_2to3_migration_client.egg-info/dependency_links.txt +1 -0
  47. data/pulp_2to3_migration_client.egg-info/requires.txt +4 -0
  48. data/pulp_2to3_migration_client.egg-info/top_level.txt +1 -0
  49. data/pulp_2to3_migration_client.gemspec +1 -1
  50. data/pulpcore/__init__.py +2 -0
  51. data/pulpcore/client/__init__.py +2 -0
  52. data/pulpcore/client/pulp_2to3_migration/__init__.py +43 -0
  53. data/pulpcore/client/pulp_2to3_migration/api/__init__.py +8 -0
  54. data/pulpcore/client/pulp_2to3_migration/api/migration_plans_api.py +761 -0
  55. data/pulpcore/client/pulp_2to3_migration/api/pulp2_content_api.py +350 -0
  56. data/pulpcore/client/pulp_2to3_migration/api/pulp2_repositories_api.py +313 -0
  57. data/pulpcore/client/pulp_2to3_migration/api_client.py +667 -0
  58. data/pulpcore/client/pulp_2to3_migration/configuration.py +427 -0
  59. data/pulpcore/client/pulp_2to3_migration/exceptions.py +121 -0
  60. data/pulpcore/client/pulp_2to3_migration/models/__init__.py +26 -0
  61. data/pulpcore/client/pulp_2to3_migration/models/async_operation_response.py +124 -0
  62. data/pulpcore/client/pulp_2to3_migration/models/migration_plan_run.py +179 -0
  63. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_migration_plan_response_list.py +197 -0
  64. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_content_response_list.py +197 -0
  65. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_repository_response_list.py +197 -0
  66. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan.py +124 -0
  67. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan_response.py +178 -0
  68. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_content_response.py +338 -0
  69. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_repository_response.py +416 -0
  70. data/pulpcore/client/pulp_2to3_migration/rest.py +292 -0
  71. data/requirements.txt +6 -0
  72. data/setup.cfg +2 -0
  73. data/setup.py +42 -0
  74. data/spec/api/migration_plans_api_spec.rb +1 -1
  75. data/spec/api/pulp2_content_api_spec.rb +1 -1
  76. data/spec/api/pulp2_repositories_api_spec.rb +1 -1
  77. data/spec/api_client_spec.rb +2 -2
  78. data/spec/configuration_spec.rb +1 -1
  79. data/spec/models/async_operation_response_spec.rb +1 -1
  80. data/spec/models/migration_plan_run_spec.rb +1 -1
  81. data/spec/models/paginatedpulp2to3_migration_migration_plan_response_list_spec.rb +1 -1
  82. data/spec/models/paginatedpulp2to3_migration_pulp2_content_response_list_spec.rb +1 -1
  83. data/spec/models/paginatedpulp2to3_migration_pulp2_repository_response_list_spec.rb +1 -1
  84. data/spec/models/pulp2to3_migration_migration_plan_response_spec.rb +1 -1
  85. data/spec/models/pulp2to3_migration_migration_plan_spec.rb +1 -1
  86. data/spec/models/pulp2to3_migration_pulp2_content_response_spec.rb +1 -1
  87. data/spec/models/pulp2to3_migration_pulp2_repository_response_spec.rb +1 -1
  88. data/spec/spec_helper.rb +1 -1
  89. data/test-requirements.txt +3 -0
  90. data/test/__init__.py +0 -0
  91. data/test/test_async_operation_response.py +54 -0
  92. data/test/test_migration_plan_run.py +55 -0
  93. data/test/test_migration_plans_api.py +76 -0
  94. data/test/test_paginatedpulp2to3_migration_migration_plan_response_list.py +61 -0
  95. data/test/test_paginatedpulp2to3_migration_pulp2_content_response_list.py +67 -0
  96. data/test/test_paginatedpulp2to3_migration_pulp2_repository_response_list.py +72 -0
  97. data/test/test_pulp2_content_api.py +48 -0
  98. data/test/test_pulp2_repositories_api.py +48 -0
  99. data/test/test_pulp2to3_migration_migration_plan.py +54 -0
  100. data/test/test_pulp2to3_migration_migration_plan_response.py +56 -0
  101. data/test/test_pulp2to3_migration_pulp2_content_response.py +65 -0
  102. data/test/test_pulp2to3_migration_pulp2_repository_response.py +69 -0
  103. data/tox.ini +9 -0
  104. metadata +74 -7
@@ -0,0 +1,427 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Pulp 3 API
5
+
6
+ Fetch, Upload, Organize, and Distribute Software Packages # noqa: E501
7
+
8
+ The version of the OpenAPI document: v3
9
+ Contact: pulp-list@redhat.com
10
+ Generated by: https://openapi-generator.tech
11
+ """
12
+
13
+
14
+ from __future__ import absolute_import
15
+
16
+ import copy
17
+ import logging
18
+ import multiprocessing
19
+ import sys
20
+ import urllib3
21
+
22
+ import six
23
+ from six.moves import http_client as httplib
24
+
25
+
26
+ class Configuration(object):
27
+ """NOTE: This class is auto generated by OpenAPI Generator
28
+
29
+ Ref: https://openapi-generator.tech
30
+ Do not edit the class manually.
31
+
32
+ :param host: Base url
33
+ :param api_key: Dict to store API key(s).
34
+ Each entry in the dict specifies an API key.
35
+ The dict key is the name of the security scheme in the OAS specification.
36
+ The dict value is the API key secret.
37
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer)
38
+ The dict key is the name of the security scheme in the OAS specification.
39
+ The dict value is an API key prefix when generating the auth data.
40
+ :param username: Username for HTTP basic authentication
41
+ :param password: Password for HTTP basic authentication
42
+ :param discard_unknown_keys: Boolean value indicating whether to discard
43
+ unknown properties. A server may send a response that includes additional
44
+ properties that are not known by the client in the following scenarios:
45
+ 1. The OpenAPI document is incomplete, i.e. it does not match the server
46
+ implementation.
47
+ 2. The client was generated using an older version of the OpenAPI document
48
+ and the server has been upgraded since then.
49
+ If a schema in the OpenAPI document defines the additionalProperties attribute,
50
+ then all undeclared properties received by the server are injected into the
51
+ additional properties map. In that case, there are undeclared properties, and
52
+ nothing to discard.
53
+
54
+ :Example:
55
+
56
+ API Key Authentication Example.
57
+ Given the following security scheme in the OpenAPI specification:
58
+ components:
59
+ securitySchemes:
60
+ cookieAuth: # name for the security scheme
61
+ type: apiKey
62
+ in: cookie
63
+ name: JSESSIONID # cookie name
64
+
65
+ You can programmatically set the cookie:
66
+
67
+ conf = pulpcore.client.pulp_2to3_migration.Configuration(
68
+ api_key={'cookieAuth': 'abc123'}
69
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
70
+ )
71
+
72
+ The following cookie will be added to the HTTP request:
73
+ Cookie: JSESSIONID abc123
74
+
75
+ HTTP Basic Authentication Example.
76
+ Given the following security scheme in the OpenAPI specification:
77
+ components:
78
+ securitySchemes:
79
+ http_basic_auth:
80
+ type: http
81
+ scheme: basic
82
+
83
+ Configure API client with HTTP basic authentication:
84
+
85
+ conf = pulpcore.client.pulp_2to3_migration.Configuration(
86
+ username='the-user',
87
+ password='the-password',
88
+ )
89
+
90
+ """
91
+
92
+ _default = None
93
+
94
+ def __init__(self, host="http://pulp",
95
+ api_key=None, api_key_prefix=None,
96
+ username=None, password=None,
97
+ discard_unknown_keys=False,
98
+ ):
99
+ """Constructor
100
+ """
101
+ self.host = host
102
+ """Default Base url
103
+ """
104
+ self.temp_folder_path = None
105
+ """Temp file folder for downloading files
106
+ """
107
+ # Authentication Settings
108
+ self.api_key = {}
109
+ if api_key:
110
+ self.api_key = api_key
111
+ """dict to store API key(s)
112
+ """
113
+ self.api_key_prefix = {}
114
+ if api_key_prefix:
115
+ self.api_key_prefix = api_key_prefix
116
+ """dict to store API prefix (e.g. Bearer)
117
+ """
118
+ self.refresh_api_key_hook = None
119
+ """function hook to refresh API key if expired
120
+ """
121
+ self.username = username
122
+ """Username for HTTP basic authentication
123
+ """
124
+ self.password = password
125
+ """Password for HTTP basic authentication
126
+ """
127
+ self.discard_unknown_keys = discard_unknown_keys
128
+ self.logger = {}
129
+ """Logging Settings
130
+ """
131
+ self.logger["package_logger"] = logging.getLogger("pulpcore.client.pulp_2to3_migration")
132
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
133
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
134
+ """Log format
135
+ """
136
+ self.logger_stream_handler = None
137
+ """Log stream handler
138
+ """
139
+ self.logger_file_handler = None
140
+ """Log file handler
141
+ """
142
+ self.logger_file = None
143
+ """Debug file location
144
+ """
145
+ self.debug = False
146
+ """Debug switch
147
+ """
148
+
149
+ self.verify_ssl = True
150
+ """SSL/TLS verification
151
+ Set this to false to skip verifying SSL certificate when calling API
152
+ from https server.
153
+ """
154
+ self.ssl_ca_cert = None
155
+ """Set this to customize the certificate file to verify the peer.
156
+ """
157
+ self.cert_file = None
158
+ """client certificate file
159
+ """
160
+ self.key_file = None
161
+ """client key file
162
+ """
163
+ self.assert_hostname = None
164
+ """Set this to True/False to enable/disable SSL hostname verification.
165
+ """
166
+
167
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
168
+ """urllib3 connection pool's maximum number of connections saved
169
+ per pool. urllib3 uses 1 connection as default value, but this is
170
+ not the best value when you are making a lot of possibly parallel
171
+ requests to the same host, which is often the case here.
172
+ cpu_count * 5 is used as default value to increase performance.
173
+ """
174
+
175
+ self.proxy = None
176
+ """Proxy URL
177
+ """
178
+ self.proxy_headers = None
179
+ """Proxy headers
180
+ """
181
+ self.safe_chars_for_path_param = '/'
182
+ """Safe chars for path_param
183
+ """
184
+ self.retries = None
185
+ """Adding retries to override urllib3 default value 3
186
+ """
187
+ # Disable client side validation
188
+ self.client_side_validation = True
189
+
190
+ def __deepcopy__(self, memo):
191
+ cls = self.__class__
192
+ result = cls.__new__(cls)
193
+ memo[id(self)] = result
194
+ for k, v in self.__dict__.items():
195
+ if k not in ('logger', 'logger_file_handler'):
196
+ setattr(result, k, copy.deepcopy(v, memo))
197
+ # shallow copy of loggers
198
+ result.logger = copy.copy(self.logger)
199
+ # use setters to configure loggers
200
+ result.logger_file = self.logger_file
201
+ result.debug = self.debug
202
+ return result
203
+
204
+ def __setattr__(self, name, value):
205
+ object.__setattr__(self, name, value)
206
+
207
+ @classmethod
208
+ def set_default(cls, default):
209
+ """Set default instance of configuration.
210
+
211
+ It stores default configuration, which can be
212
+ returned by get_default_copy method.
213
+
214
+ :param default: object of Configuration
215
+ """
216
+ cls._default = copy.deepcopy(default)
217
+
218
+ @classmethod
219
+ def get_default_copy(cls):
220
+ """Return new instance of configuration.
221
+
222
+ This method returns newly created, based on default constructor,
223
+ object of Configuration class or returns a copy of default
224
+ configuration passed by the set_default method.
225
+
226
+ :return: The configuration object.
227
+ """
228
+ if cls._default is not None:
229
+ return copy.deepcopy(cls._default)
230
+ return Configuration()
231
+
232
+ @property
233
+ def logger_file(self):
234
+ """The logger file.
235
+
236
+ If the logger_file is None, then add stream handler and remove file
237
+ handler. Otherwise, add file handler and remove stream handler.
238
+
239
+ :param value: The logger_file path.
240
+ :type: str
241
+ """
242
+ return self.__logger_file
243
+
244
+ @logger_file.setter
245
+ def logger_file(self, value):
246
+ """The logger file.
247
+
248
+ If the logger_file is None, then add stream handler and remove file
249
+ handler. Otherwise, add file handler and remove stream handler.
250
+
251
+ :param value: The logger_file path.
252
+ :type: str
253
+ """
254
+ self.__logger_file = value
255
+ if self.__logger_file:
256
+ # If set logging file,
257
+ # then add file handler and remove stream handler.
258
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
259
+ self.logger_file_handler.setFormatter(self.logger_formatter)
260
+ for _, logger in six.iteritems(self.logger):
261
+ logger.addHandler(self.logger_file_handler)
262
+
263
+ @property
264
+ def debug(self):
265
+ """Debug status
266
+
267
+ :param value: The debug status, True or False.
268
+ :type: bool
269
+ """
270
+ return self.__debug
271
+
272
+ @debug.setter
273
+ def debug(self, value):
274
+ """Debug status
275
+
276
+ :param value: The debug status, True or False.
277
+ :type: bool
278
+ """
279
+ self.__debug = value
280
+ if self.__debug:
281
+ # if debug status is True, turn on debug logging
282
+ for _, logger in six.iteritems(self.logger):
283
+ logger.setLevel(logging.DEBUG)
284
+ # turn on httplib debug
285
+ httplib.HTTPConnection.debuglevel = 1
286
+ else:
287
+ # if debug status is False, turn off debug logging,
288
+ # setting log level to default `logging.WARNING`
289
+ for _, logger in six.iteritems(self.logger):
290
+ logger.setLevel(logging.WARNING)
291
+ # turn off httplib debug
292
+ httplib.HTTPConnection.debuglevel = 0
293
+
294
+ @property
295
+ def logger_format(self):
296
+ """The logger format.
297
+
298
+ The logger_formatter will be updated when sets logger_format.
299
+
300
+ :param value: The format string.
301
+ :type: str
302
+ """
303
+ return self.__logger_format
304
+
305
+ @logger_format.setter
306
+ def logger_format(self, value):
307
+ """The logger format.
308
+
309
+ The logger_formatter will be updated when sets logger_format.
310
+
311
+ :param value: The format string.
312
+ :type: str
313
+ """
314
+ self.__logger_format = value
315
+ self.logger_formatter = logging.Formatter(self.__logger_format)
316
+
317
+ def get_api_key_with_prefix(self, identifier):
318
+ """Gets API key (with prefix if set).
319
+
320
+ :param identifier: The identifier of apiKey.
321
+ :return: The token for api key authentication.
322
+ """
323
+ if self.refresh_api_key_hook is not None:
324
+ self.refresh_api_key_hook(self)
325
+ key = self.api_key.get(identifier)
326
+ if key:
327
+ prefix = self.api_key_prefix.get(identifier)
328
+ if prefix:
329
+ return "%s %s" % (prefix, key)
330
+ else:
331
+ return key
332
+
333
+ def get_basic_auth_token(self):
334
+ """Gets HTTP basic authentication header (string).
335
+
336
+ :return: The token for basic HTTP authentication.
337
+ """
338
+ username = ""
339
+ if self.username is not None:
340
+ username = self.username
341
+ password = ""
342
+ if self.password is not None:
343
+ password = self.password
344
+ return urllib3.util.make_headers(
345
+ basic_auth=username + ':' + password
346
+ ).get('authorization')
347
+
348
+ def auth_settings(self):
349
+ """Gets Auth Settings dict for api client.
350
+
351
+ :return: The Auth Settings information dict.
352
+ """
353
+ auth = {}
354
+ if self.username is not None and self.password is not None:
355
+ auth['basicAuth'] = {
356
+ 'type': 'basic',
357
+ 'in': 'header',
358
+ 'key': 'Authorization',
359
+ 'value': self.get_basic_auth_token()
360
+ }
361
+ if 'Session' in self.api_key:
362
+ auth['cookieAuth'] = {
363
+ 'type': 'api_key',
364
+ 'in': 'cookie',
365
+ 'key': 'Session',
366
+ 'value': self.get_api_key_with_prefix('Session')
367
+ }
368
+ return auth
369
+
370
+ def to_debug_report(self):
371
+ """Gets the essential information for debugging.
372
+
373
+ :return: The report for debugging.
374
+ """
375
+ return "Python SDK Debug Report:\n"\
376
+ "OS: {env}\n"\
377
+ "Python Version: {pyversion}\n"\
378
+ "Version of the API: v3\n"\
379
+ "SDK Package Version: 0.12.0.dev1624592827".\
380
+ format(env=sys.platform, pyversion=sys.version)
381
+
382
+ def get_host_settings(self):
383
+ """Gets an array of host settings
384
+
385
+ :return: An array of host settings
386
+ """
387
+ return [
388
+ {
389
+ 'url': "http://pulp/",
390
+ 'description': "No description provided",
391
+ }
392
+ ]
393
+
394
+ def get_host_from_settings(self, index, variables=None):
395
+ """Gets host URL based on the index and variables
396
+ :param index: array index of the host settings
397
+ :param variables: hash of variable and the corresponding value
398
+ :return: URL based on host settings
399
+ """
400
+ variables = {} if variables is None else variables
401
+ servers = self.get_host_settings()
402
+
403
+ try:
404
+ server = servers[index]
405
+ except IndexError:
406
+ raise ValueError(
407
+ "Invalid index {0} when selecting the host settings. "
408
+ "Must be less than {1}".format(index, len(servers)))
409
+
410
+ url = server['url']
411
+
412
+ # go through variables and replace placeholders
413
+ for variable_name, variable in server['variables'].items():
414
+ used_value = variables.get(
415
+ variable_name, variable['default_value'])
416
+
417
+ if 'enum_values' in variable \
418
+ and used_value not in variable['enum_values']:
419
+ raise ValueError(
420
+ "The variable `{0}` in the host URL has invalid value "
421
+ "{1}. Must be {2}.".format(
422
+ variable_name, variables[variable_name],
423
+ variable['enum_values']))
424
+
425
+ url = url.replace("{" + variable_name + "}", used_value)
426
+
427
+ return url
@@ -0,0 +1,121 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Pulp 3 API
5
+
6
+ Fetch, Upload, Organize, and Distribute Software Packages # noqa: E501
7
+
8
+ The version of the OpenAPI document: v3
9
+ Contact: pulp-list@redhat.com
10
+ Generated by: https://openapi-generator.tech
11
+ """
12
+
13
+
14
+ import six
15
+
16
+
17
+ class OpenApiException(Exception):
18
+ """The base exception class for all OpenAPIExceptions"""
19
+
20
+
21
+ class ApiTypeError(OpenApiException, TypeError):
22
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
23
+ key_type=None):
24
+ """ Raises an exception for TypeErrors
25
+
26
+ Args:
27
+ msg (str): the exception message
28
+
29
+ Keyword Args:
30
+ path_to_item (list): a list of keys an indices to get to the
31
+ current_item
32
+ None if unset
33
+ valid_classes (tuple): the primitive classes that current item
34
+ should be an instance of
35
+ None if unset
36
+ key_type (bool): False if our value is a value in a dict
37
+ True if it is a key in a dict
38
+ False if our item is an item in a list
39
+ None if unset
40
+ """
41
+ self.path_to_item = path_to_item
42
+ self.valid_classes = valid_classes
43
+ self.key_type = key_type
44
+ full_msg = msg
45
+ if path_to_item:
46
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
47
+ super(ApiTypeError, self).__init__(full_msg)
48
+
49
+
50
+ class ApiValueError(OpenApiException, ValueError):
51
+ def __init__(self, msg, path_to_item=None):
52
+ """
53
+ Args:
54
+ msg (str): the exception message
55
+
56
+ Keyword Args:
57
+ path_to_item (list) the path to the exception in the
58
+ received_data dict. None if unset
59
+ """
60
+
61
+ self.path_to_item = path_to_item
62
+ full_msg = msg
63
+ if path_to_item:
64
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
65
+ super(ApiValueError, self).__init__(full_msg)
66
+
67
+
68
+ class ApiKeyError(OpenApiException, KeyError):
69
+ def __init__(self, msg, path_to_item=None):
70
+ """
71
+ Args:
72
+ msg (str): the exception message
73
+
74
+ Keyword Args:
75
+ path_to_item (None/list) the path to the exception in the
76
+ received_data dict
77
+ """
78
+ self.path_to_item = path_to_item
79
+ full_msg = msg
80
+ if path_to_item:
81
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
82
+ super(ApiKeyError, self).__init__(full_msg)
83
+
84
+
85
+ class ApiException(OpenApiException):
86
+
87
+ def __init__(self, status=None, reason=None, http_resp=None):
88
+ if http_resp:
89
+ self.status = http_resp.status
90
+ self.reason = http_resp.reason
91
+ self.body = http_resp.data
92
+ self.headers = http_resp.getheaders()
93
+ else:
94
+ self.status = status
95
+ self.reason = reason
96
+ self.body = None
97
+ self.headers = None
98
+
99
+ def __str__(self):
100
+ """Custom error messages for exception"""
101
+ error_message = "({0})\n"\
102
+ "Reason: {1}\n".format(self.status, self.reason)
103
+ if self.headers:
104
+ error_message += "HTTP response headers: {0}\n".format(
105
+ self.headers)
106
+
107
+ if self.body:
108
+ error_message += "HTTP response body: {0}\n".format(self.body)
109
+
110
+ return error_message
111
+
112
+
113
+ def render_path(path_to_item):
114
+ """Returns a string representation of a path"""
115
+ result = ""
116
+ for pth in path_to_item:
117
+ if isinstance(pth, six.integer_types):
118
+ result += "[{0}]".format(pth)
119
+ else:
120
+ result += "['{0}']".format(pth)
121
+ return result