pulp_maven_client 0.3.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +6 -7
  4. data/docs/ContentArtifactApi.md +3 -3
  5. data/docs/DistributionsMavenApi.md +3 -3
  6. data/docs/MavenMavenRemote.md +10 -8
  7. data/docs/MavenMavenRemoteResponse.md +8 -6
  8. data/docs/MavenMavenRepository.md +3 -1
  9. data/docs/MavenMavenRepositoryResponse.md +3 -1
  10. data/docs/PatchedmavenMavenRemote.md +10 -8
  11. data/docs/PatchedmavenMavenRepository.md +3 -1
  12. data/docs/RemotesMavenApi.md +3 -3
  13. data/docs/Repair.md +17 -0
  14. data/docs/RepositoriesMavenApi.md +3 -3
  15. data/docs/RepositoriesMavenVersionsApi.md +7 -7
  16. data/docs/RepositoryVersionResponse.md +2 -0
  17. data/lib/pulp_maven_client/api/content_artifact_api.rb +8 -4
  18. data/lib/pulp_maven_client/api/distributions_maven_api.rb +8 -4
  19. data/lib/pulp_maven_client/api/remotes_maven_api.rb +8 -4
  20. data/lib/pulp_maven_client/api/repositories_maven_api.rb +8 -4
  21. data/lib/pulp_maven_client/api/repositories_maven_versions_api.rb +17 -13
  22. data/lib/pulp_maven_client/api_client.rb +13 -12
  23. data/lib/pulp_maven_client/api_error.rb +1 -1
  24. data/lib/pulp_maven_client/configuration.rb +11 -3
  25. data/lib/pulp_maven_client/models/async_operation_response.rb +1 -1
  26. data/lib/pulp_maven_client/models/content_summary_response.rb +1 -1
  27. data/lib/pulp_maven_client/models/maven_maven_artifact.rb +20 -1
  28. data/lib/pulp_maven_client/models/maven_maven_artifact_response.rb +1 -1
  29. data/lib/pulp_maven_client/models/maven_maven_distribution.rb +39 -1
  30. data/lib/pulp_maven_client/models/maven_maven_distribution_response.rb +1 -1
  31. data/lib/pulp_maven_client/models/maven_maven_remote.rb +180 -10
  32. data/lib/pulp_maven_client/models/maven_maven_remote_response.rb +20 -8
  33. data/lib/pulp_maven_client/models/maven_maven_repository.rb +63 -2
  34. data/lib/pulp_maven_client/models/maven_maven_repository_response.rb +29 -2
  35. data/lib/pulp_maven_client/models/paginated_repository_version_response_list.rb +1 -1
  36. data/lib/pulp_maven_client/models/paginatedmaven_maven_artifact_response_list.rb +1 -1
  37. data/lib/pulp_maven_client/models/paginatedmaven_maven_distribution_response_list.rb +1 -1
  38. data/lib/pulp_maven_client/models/paginatedmaven_maven_remote_response_list.rb +1 -1
  39. data/lib/pulp_maven_client/models/paginatedmaven_maven_repository_response_list.rb +1 -1
  40. data/lib/pulp_maven_client/models/patchedmaven_maven_distribution.rb +31 -1
  41. data/lib/pulp_maven_client/models/patchedmaven_maven_remote.rb +172 -10
  42. data/lib/pulp_maven_client/models/patchedmaven_maven_repository.rb +59 -2
  43. data/lib/pulp_maven_client/models/policy_enum.rb +1 -1
  44. data/lib/pulp_maven_client/models/{repository_version.rb → repair.rb} +14 -13
  45. data/lib/pulp_maven_client/models/repository_version_response.rb +11 -2
  46. data/lib/pulp_maven_client/version.rb +2 -2
  47. data/lib/pulp_maven_client.rb +2 -3
  48. data/pulp_maven_client.gemspec +2 -2
  49. data/spec/api/content_artifact_api_spec.rb +2 -2
  50. data/spec/api/distributions_maven_api_spec.rb +2 -2
  51. data/spec/api/remotes_maven_api_spec.rb +2 -2
  52. data/spec/api/repositories_maven_api_spec.rb +2 -2
  53. data/spec/api/repositories_maven_versions_api_spec.rb +3 -3
  54. data/spec/api_client_spec.rb +2 -2
  55. data/spec/configuration_spec.rb +4 -4
  56. data/spec/models/async_operation_response_spec.rb +1 -1
  57. data/spec/models/content_summary_response_spec.rb +1 -1
  58. data/spec/models/maven_maven_artifact_response_spec.rb +1 -1
  59. data/spec/models/maven_maven_artifact_spec.rb +1 -1
  60. data/spec/models/maven_maven_distribution_response_spec.rb +1 -1
  61. data/spec/models/maven_maven_distribution_spec.rb +1 -1
  62. data/spec/models/maven_maven_remote_response_spec.rb +7 -1
  63. data/spec/models/maven_maven_remote_spec.rb +7 -1
  64. data/spec/models/maven_maven_repository_response_spec.rb +7 -1
  65. data/spec/models/maven_maven_repository_spec.rb +7 -1
  66. data/spec/models/paginated_repository_version_response_list_spec.rb +1 -1
  67. data/spec/models/paginatedmaven_maven_artifact_response_list_spec.rb +1 -1
  68. data/spec/models/paginatedmaven_maven_distribution_response_list_spec.rb +1 -1
  69. data/spec/models/paginatedmaven_maven_remote_response_list_spec.rb +1 -1
  70. data/spec/models/paginatedmaven_maven_repository_response_list_spec.rb +1 -1
  71. data/spec/models/patchedmaven_maven_distribution_spec.rb +1 -1
  72. data/spec/models/patchedmaven_maven_remote_spec.rb +7 -1
  73. data/spec/models/patchedmaven_maven_repository_spec.rb +7 -1
  74. data/spec/models/policy_enum_spec.rb +1 -1
  75. data/spec/models/{repository_version_spec.rb → repair_spec.rb} +8 -8
  76. data/spec/models/repository_version_response_spec.rb +7 -1
  77. data/spec/spec_helper.rb +1 -1
  78. metadata +31 -141
  79. data/build/lib/pulpcore/__init__.py +0 -2
  80. data/build/lib/pulpcore/client/__init__.py +0 -2
  81. data/build/lib/pulpcore/client/pulp_maven/__init__.py +0 -58
  82. data/build/lib/pulpcore/client/pulp_maven/api/__init__.py +0 -10
  83. data/build/lib/pulpcore/client/pulp_maven/api/content_artifact_api.py +0 -445
  84. data/build/lib/pulpcore/client/pulp_maven/api/distributions_maven_api.py +0 -830
  85. data/build/lib/pulpcore/client/pulp_maven/api/remotes_maven_api.py +0 -840
  86. data/build/lib/pulpcore/client/pulp_maven/api/repositories_maven_api.py +0 -809
  87. data/build/lib/pulpcore/client/pulp_maven/api/repositories_maven_versions_api.py +0 -614
  88. data/build/lib/pulpcore/client/pulp_maven/api_client.py +0 -667
  89. data/build/lib/pulpcore/client/pulp_maven/configuration.py +0 -427
  90. data/build/lib/pulpcore/client/pulp_maven/exceptions.py +0 -121
  91. data/build/lib/pulpcore/client/pulp_maven/models/__init__.py +0 -39
  92. data/build/lib/pulpcore/client/pulp_maven/models/async_operation_response.py +0 -124
  93. data/build/lib/pulpcore/client/pulp_maven/models/content_summary.py +0 -176
  94. data/build/lib/pulpcore/client/pulp_maven/models/content_summary_response.py +0 -176
  95. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_artifact.py +0 -153
  96. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_artifact_response.py +0 -290
  97. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_distribution.py +0 -260
  98. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_distribution_response.py +0 -342
  99. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_remote.py +0 -657
  100. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_remote_response.py +0 -604
  101. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_repository.py +0 -202
  102. data/build/lib/pulpcore/client/pulp_maven/models/maven_maven_repository_response.py +0 -308
  103. data/build/lib/pulpcore/client/pulp_maven/models/paginated_repository_version_response_list.py +0 -197
  104. data/build/lib/pulpcore/client/pulp_maven/models/paginatedmaven_maven_artifact_response_list.py +0 -197
  105. data/build/lib/pulpcore/client/pulp_maven/models/paginatedmaven_maven_distribution_response_list.py +0 -197
  106. data/build/lib/pulpcore/client/pulp_maven/models/paginatedmaven_maven_remote_response_list.py +0 -197
  107. data/build/lib/pulpcore/client/pulp_maven/models/paginatedmaven_maven_repository_response_list.py +0 -197
  108. data/build/lib/pulpcore/client/pulp_maven/models/patchedmaven_maven_distribution.py +0 -258
  109. data/build/lib/pulpcore/client/pulp_maven/models/patchedmaven_maven_remote.py +0 -655
  110. data/build/lib/pulpcore/client/pulp_maven/models/patchedmaven_maven_repository.py +0 -201
  111. data/build/lib/pulpcore/client/pulp_maven/models/policy_enum.py +0 -101
  112. data/build/lib/pulpcore/client/pulp_maven/models/repository_version.py +0 -123
  113. data/build/lib/pulpcore/client/pulp_maven/models/repository_version_response.py +0 -231
  114. data/build/lib/pulpcore/client/pulp_maven/rest.py +0 -292
  115. data/dist/pulp_maven-client-0.3.0.tar.gz +0 -0
  116. data/dist/pulp_maven_client-0.3.0-py3-none-any.whl +0 -0
  117. data/docs/ContentSummary.md +0 -21
  118. data/docs/RepositoryVersion.md +0 -17
  119. data/lib/pulp_maven_client/models/content_summary.rb +0 -246
  120. data/pulp_maven_client.egg-info/PKG-INFO +0 -15
  121. data/pulp_maven_client.egg-info/SOURCES.txt +0 -71
  122. data/pulp_maven_client.egg-info/dependency_links.txt +0 -1
  123. data/pulp_maven_client.egg-info/requires.txt +0 -4
  124. data/pulp_maven_client.egg-info/top_level.txt +0 -1
  125. data/pulpcore/__init__.py +0 -2
  126. data/pulpcore/client/__init__.py +0 -2
  127. data/pulpcore/client/pulp_maven/__init__.py +0 -58
  128. data/pulpcore/client/pulp_maven/api/__init__.py +0 -10
  129. data/pulpcore/client/pulp_maven/api/content_artifact_api.py +0 -445
  130. data/pulpcore/client/pulp_maven/api/distributions_maven_api.py +0 -830
  131. data/pulpcore/client/pulp_maven/api/remotes_maven_api.py +0 -840
  132. data/pulpcore/client/pulp_maven/api/repositories_maven_api.py +0 -809
  133. data/pulpcore/client/pulp_maven/api/repositories_maven_versions_api.py +0 -614
  134. data/pulpcore/client/pulp_maven/api_client.py +0 -667
  135. data/pulpcore/client/pulp_maven/configuration.py +0 -427
  136. data/pulpcore/client/pulp_maven/exceptions.py +0 -121
  137. data/pulpcore/client/pulp_maven/models/__init__.py +0 -39
  138. data/pulpcore/client/pulp_maven/models/async_operation_response.py +0 -124
  139. data/pulpcore/client/pulp_maven/models/content_summary.py +0 -176
  140. data/pulpcore/client/pulp_maven/models/content_summary_response.py +0 -176
  141. data/pulpcore/client/pulp_maven/models/maven_maven_artifact.py +0 -153
  142. data/pulpcore/client/pulp_maven/models/maven_maven_artifact_response.py +0 -290
  143. data/pulpcore/client/pulp_maven/models/maven_maven_distribution.py +0 -260
  144. data/pulpcore/client/pulp_maven/models/maven_maven_distribution_response.py +0 -342
  145. data/pulpcore/client/pulp_maven/models/maven_maven_remote.py +0 -657
  146. data/pulpcore/client/pulp_maven/models/maven_maven_remote_response.py +0 -604
  147. data/pulpcore/client/pulp_maven/models/maven_maven_repository.py +0 -202
  148. data/pulpcore/client/pulp_maven/models/maven_maven_repository_response.py +0 -308
  149. data/pulpcore/client/pulp_maven/models/paginated_repository_version_response_list.py +0 -197
  150. data/pulpcore/client/pulp_maven/models/paginatedmaven_maven_artifact_response_list.py +0 -197
  151. data/pulpcore/client/pulp_maven/models/paginatedmaven_maven_distribution_response_list.py +0 -197
  152. data/pulpcore/client/pulp_maven/models/paginatedmaven_maven_remote_response_list.py +0 -197
  153. data/pulpcore/client/pulp_maven/models/paginatedmaven_maven_repository_response_list.py +0 -197
  154. data/pulpcore/client/pulp_maven/models/patchedmaven_maven_distribution.py +0 -258
  155. data/pulpcore/client/pulp_maven/models/patchedmaven_maven_remote.py +0 -655
  156. data/pulpcore/client/pulp_maven/models/patchedmaven_maven_repository.py +0 -201
  157. data/pulpcore/client/pulp_maven/models/policy_enum.py +0 -101
  158. data/pulpcore/client/pulp_maven/models/repository_version.py +0 -123
  159. data/pulpcore/client/pulp_maven/models/repository_version_response.py +0 -231
  160. data/pulpcore/client/pulp_maven/rest.py +0 -292
  161. data/requirements.txt +0 -6
  162. data/setup.cfg +0 -2
  163. data/setup.py +0 -42
  164. data/spec/models/content_summary_spec.rb +0 -53
  165. data/test/__init__.py +0 -0
  166. data/test/test_async_operation_response.py +0 -54
  167. data/test/test_content_artifact_api.py +0 -55
  168. data/test/test_content_summary.py +0 -70
  169. data/test/test_content_summary_response.py +0 -70
  170. data/test/test_distributions_maven_api.py +0 -76
  171. data/test/test_maven_maven_artifact.py +0 -56
  172. data/test/test_maven_maven_artifact_response.py +0 -60
  173. data/test/test_maven_maven_distribution.py +0 -60
  174. data/test/test_maven_maven_distribution_response.py +0 -63
  175. data/test/test_maven_maven_remote.py +0 -76
  176. data/test/test_maven_maven_remote_response.py +0 -74
  177. data/test/test_maven_maven_repository.py +0 -57
  178. data/test/test_maven_maven_repository_response.py +0 -61
  179. data/test/test_paginated_repository_version_response_list.py +0 -63
  180. data/test/test_paginatedmaven_maven_artifact_response_list.py +0 -65
  181. data/test/test_paginatedmaven_maven_distribution_response_list.py +0 -67
  182. data/test/test_paginatedmaven_maven_remote_response_list.py +0 -78
  183. data/test/test_paginatedmaven_maven_repository_response_list.py +0 -66
  184. data/test/test_patchedmaven_maven_distribution.py +0 -58
  185. data/test/test_patchedmaven_maven_remote.py +0 -74
  186. data/test/test_patchedmaven_maven_repository.py +0 -56
  187. data/test/test_policy_enum.py +0 -52
  188. data/test/test_remotes_maven_api.py +0 -76
  189. data/test/test_repositories_maven_api.py +0 -76
  190. data/test/test_repositories_maven_versions_api.py +0 -61
  191. data/test/test_repository_version.py +0 -53
  192. data/test/test_repository_version_response.py +0 -57
  193. data/test-requirements.txt +0 -3
  194. data/tox.ini +0 -9
@@ -1,667 +0,0 @@
1
- # coding: utf-8
2
- """
3
- Pulp 3 API
4
-
5
- Fetch, Upload, Organize, and Distribute Software Packages # noqa: E501
6
-
7
- The version of the OpenAPI document: v3
8
- Contact: pulp-list@redhat.com
9
- Generated by: https://openapi-generator.tech
10
- """
11
-
12
- from __future__ import absolute_import
13
-
14
- import atexit
15
- import datetime
16
- from dateutil.parser import parse
17
- import json
18
- import mimetypes
19
- from multiprocessing.pool import ThreadPool
20
- import os
21
- import re
22
- import tempfile
23
-
24
- # python 2 and python 3 compatibility library
25
- import six
26
- from six.moves.urllib.parse import quote
27
-
28
- from pulpcore.client.pulp_maven.configuration import Configuration
29
- import pulpcore.client.pulp_maven.models
30
- from pulpcore.client.pulp_maven import rest
31
- from pulpcore.client.pulp_maven.exceptions import ApiValueError, ApiException
32
-
33
-
34
- class ApiClient(object):
35
- """Generic API client for OpenAPI client library builds.
36
-
37
- OpenAPI generic API client. This client handles the client-
38
- server communication, and is invariant across implementations. Specifics of
39
- the methods and models for each application are generated from the OpenAPI
40
- templates.
41
-
42
- NOTE: This class is auto generated by OpenAPI Generator.
43
- Ref: https://openapi-generator.tech
44
- Do not edit the class manually.
45
-
46
- :param configuration: .Configuration object for this client
47
- :param header_name: a header to pass when making calls to the API.
48
- :param header_value: a header value to pass when making calls to
49
- the API.
50
- :param cookie: a cookie to include in the header when making calls
51
- to the API
52
- :param pool_threads: The number of threads to use for async requests
53
- to the API. More threads means more concurrent API requests.
54
- """
55
-
56
- PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
57
- NATIVE_TYPES_MAPPING = {
58
- 'int': int,
59
- 'long': int if six.PY3 else long, # noqa: F821
60
- 'float': float,
61
- 'str': str,
62
- 'bool': bool,
63
- 'date': datetime.date,
64
- 'datetime': datetime.datetime,
65
- 'object': object,
66
- }
67
- _pool = None
68
-
69
- def __init__(self, configuration=None, header_name=None, header_value=None,
70
- cookie=None, pool_threads=1):
71
- if configuration is None:
72
- configuration = Configuration.get_default_copy()
73
- self.configuration = configuration
74
- self.pool_threads = pool_threads
75
-
76
- self.rest_client = rest.RESTClientObject(configuration)
77
- self.default_headers = {}
78
- if header_name is not None:
79
- self.default_headers[header_name] = header_value
80
- self.cookie = cookie
81
- # Set default User-Agent.
82
- self.user_agent = 'OpenAPI-Generator/0.3.0/python'
83
- self.client_side_validation = configuration.client_side_validation
84
-
85
- def __enter__(self):
86
- return self
87
-
88
- def __exit__(self, exc_type, exc_value, traceback):
89
- self.close()
90
-
91
- def close(self):
92
- if self._pool:
93
- self._pool.close()
94
- self._pool.join()
95
- self._pool = None
96
- if hasattr(atexit, 'unregister'):
97
- atexit.unregister(self.close)
98
-
99
- @property
100
- def pool(self):
101
- """Create thread pool on first request
102
- avoids instantiating unused threadpool for blocking clients.
103
- """
104
- if self._pool is None:
105
- atexit.register(self.close)
106
- self._pool = ThreadPool(self.pool_threads)
107
- return self._pool
108
-
109
- @property
110
- def user_agent(self):
111
- """User agent for this API client"""
112
- return self.default_headers['User-Agent']
113
-
114
- @user_agent.setter
115
- def user_agent(self, value):
116
- self.default_headers['User-Agent'] = value
117
-
118
- def set_default_header(self, header_name, header_value):
119
- self.default_headers[header_name] = header_value
120
-
121
- def __call_api(
122
- self, resource_path, method, path_params=None,
123
- query_params=None, header_params=None, body=None, post_params=None,
124
- files=None, response_type=None, auth_settings=None,
125
- _return_http_data_only=None, collection_formats=None,
126
- _preload_content=True, _request_timeout=None, _host=None):
127
-
128
- config = self.configuration
129
-
130
- # header parameters
131
- header_params = header_params or {}
132
- header_params.update(self.default_headers)
133
- if self.cookie:
134
- header_params['Cookie'] = self.cookie
135
- if header_params:
136
- header_params = self.sanitize_for_serialization(header_params)
137
- header_params = dict(self.parameters_to_tuples(header_params,
138
- collection_formats))
139
-
140
- # path parameters
141
- if path_params:
142
- path_params = self.sanitize_for_serialization(path_params)
143
- path_params = self.parameters_to_tuples(path_params,
144
- collection_formats)
145
- for k, v in path_params:
146
- # specified safe chars, encode everything
147
- resource_path = resource_path.replace(
148
- '{%s}' % k,
149
- quote(str(v), safe=config.safe_chars_for_path_param)
150
- )
151
-
152
- # query parameters
153
- if query_params:
154
- query_params = self.sanitize_for_serialization(query_params)
155
- query_params = self.parameters_to_tuples(query_params,
156
- collection_formats)
157
-
158
- # post parameters
159
- if post_params or files:
160
- post_params = post_params if post_params else []
161
- post_params = self.sanitize_for_serialization(post_params)
162
- post_params = self.parameters_to_tuples(post_params,
163
- collection_formats)
164
- post_params.extend(self.files_parameters(files))
165
-
166
- # auth setting
167
- self.update_params_for_auth(header_params, query_params, auth_settings)
168
-
169
- # body
170
- if body:
171
- body = self.sanitize_for_serialization(body)
172
-
173
- # request url
174
- if _host is None:
175
- url = self.configuration.host + resource_path
176
- else:
177
- # use server/host defined in path or operation instead
178
- url = _host + resource_path
179
-
180
- try:
181
- # perform request and return response
182
- response_data = self.request(
183
- method, url, query_params=query_params, headers=header_params,
184
- post_params=post_params, body=body,
185
- _preload_content=_preload_content,
186
- _request_timeout=_request_timeout)
187
- except ApiException as e:
188
- e.body = e.body.decode('utf-8') if six.PY3 else e.body
189
- raise e
190
-
191
- content_type = response_data.getheader('content-type')
192
-
193
- self.last_response = response_data
194
-
195
- return_data = response_data
196
-
197
- if not _preload_content:
198
- return return_data
199
-
200
- if six.PY3 and response_type not in ["file", "bytes"]:
201
- match = None
202
- if content_type is not None:
203
- match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
204
- encoding = match.group(1) if match else "utf-8"
205
- response_data.data = response_data.data.decode(encoding)
206
-
207
- # deserialize response data
208
- if response_type:
209
- return_data = self.deserialize(response_data, response_type)
210
- else:
211
- return_data = None
212
-
213
- if _return_http_data_only:
214
- return (return_data)
215
- else:
216
- return (return_data, response_data.status,
217
- response_data.getheaders())
218
-
219
- def sanitize_for_serialization(self, obj):
220
- """Builds a JSON POST object.
221
-
222
- If obj is None, return None.
223
- If obj is str, int, long, float, bool, return directly.
224
- If obj is datetime.datetime, datetime.date
225
- convert to string in iso8601 format.
226
- If obj is list, sanitize each element in the list.
227
- If obj is dict, return the dict.
228
- If obj is OpenAPI model, return the properties dict.
229
-
230
- :param obj: The data to serialize.
231
- :return: The serialized form of data.
232
- """
233
- if obj is None:
234
- return None
235
- elif isinstance(obj, self.PRIMITIVE_TYPES):
236
- return obj
237
- elif isinstance(obj, list):
238
- return [self.sanitize_for_serialization(sub_obj)
239
- for sub_obj in obj]
240
- elif isinstance(obj, tuple):
241
- return tuple(self.sanitize_for_serialization(sub_obj)
242
- for sub_obj in obj)
243
- elif isinstance(obj, (datetime.datetime, datetime.date)):
244
- return obj.isoformat()
245
-
246
- if isinstance(obj, dict):
247
- obj_dict = obj
248
- else:
249
- # Convert model obj to dict except
250
- # attributes `openapi_types`, `attribute_map`
251
- # and attributes which value is not None.
252
- # Convert attribute name to json key in
253
- # model definition for request.
254
- obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
255
- for attr, _ in six.iteritems(obj.openapi_types)
256
- if getattr(obj, attr) is not None}
257
-
258
- return {key: self.sanitize_for_serialization(val)
259
- for key, val in six.iteritems(obj_dict)}
260
-
261
- def deserialize(self, response, response_type):
262
- """Deserializes response into an object.
263
-
264
- :param response: RESTResponse object to be deserialized.
265
- :param response_type: class literal for
266
- deserialized object, or string of class name.
267
-
268
- :return: deserialized object.
269
- """
270
- # handle file downloading
271
- # save response body into a tmp file and return the instance
272
- if response_type == "file":
273
- return self.__deserialize_file(response)
274
-
275
- # fetch data from response object
276
- try:
277
- data = json.loads(response.data)
278
- except ValueError:
279
- data = response.data
280
-
281
- return self.__deserialize(data, response_type)
282
-
283
- def __deserialize(self, data, klass):
284
- """Deserializes dict, list, str into an object.
285
-
286
- :param data: dict, list or str.
287
- :param klass: class literal, or string of class name.
288
-
289
- :return: object.
290
- """
291
- if data is None:
292
- return None
293
-
294
- if type(klass) == str:
295
- if klass.startswith('list['):
296
- sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
297
- return [self.__deserialize(sub_data, sub_kls)
298
- for sub_data in data]
299
-
300
- if klass.startswith('dict('):
301
- sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2)
302
- return {k: self.__deserialize(v, sub_kls)
303
- for k, v in six.iteritems(data)}
304
-
305
- # convert str to class
306
- if klass in self.NATIVE_TYPES_MAPPING:
307
- klass = self.NATIVE_TYPES_MAPPING[klass]
308
- else:
309
- klass = getattr(pulpcore.client.pulp_maven.models, klass)
310
-
311
- if klass in self.PRIMITIVE_TYPES:
312
- return self.__deserialize_primitive(data, klass)
313
- elif klass == object:
314
- return self.__deserialize_object(data)
315
- elif klass == datetime.date:
316
- return self.__deserialize_date(data)
317
- elif klass == datetime.datetime:
318
- return self.__deserialize_datetime(data)
319
- else:
320
- return self.__deserialize_model(data, klass)
321
-
322
- def call_api(self, resource_path, method,
323
- path_params=None, query_params=None, header_params=None,
324
- body=None, post_params=None, files=None,
325
- response_type=None, auth_settings=None, async_req=None,
326
- _return_http_data_only=None, collection_formats=None,
327
- _preload_content=True, _request_timeout=None, _host=None):
328
- """Makes the HTTP request (synchronous) and returns deserialized data.
329
-
330
- To make an async_req request, set the async_req parameter.
331
-
332
- :param resource_path: Path to method endpoint.
333
- :param method: Method to call.
334
- :param path_params: Path parameters in the url.
335
- :param query_params: Query parameters in the url.
336
- :param header_params: Header parameters to be
337
- placed in the request header.
338
- :param body: Request body.
339
- :param post_params dict: Request post form parameters,
340
- for `application/x-www-form-urlencoded`, `multipart/form-data`.
341
- :param auth_settings list: Auth Settings names for the request.
342
- :param response: Response data type.
343
- :param files dict: key -> filename, value -> filepath,
344
- for `multipart/form-data`.
345
- :param async_req bool: execute request asynchronously
346
- :param _return_http_data_only: response data without head status code
347
- and headers
348
- :param collection_formats: dict of collection formats for path, query,
349
- header, and post parameters.
350
- :param _preload_content: if False, the urllib3.HTTPResponse object will
351
- be returned without reading/decoding response
352
- data. Default is True.
353
- :param _request_timeout: timeout setting for this request. If one
354
- number provided, it will be total request
355
- timeout. It can also be a pair (tuple) of
356
- (connection, read) timeouts.
357
- :return:
358
- If async_req parameter is True,
359
- the request will be called asynchronously.
360
- The method will return the request thread.
361
- If parameter async_req is False or missing,
362
- then the method will return the response directly.
363
- """
364
- if not async_req:
365
- return self.__call_api(resource_path, method,
366
- path_params, query_params, header_params,
367
- body, post_params, files,
368
- response_type, auth_settings,
369
- _return_http_data_only, collection_formats,
370
- _preload_content, _request_timeout, _host)
371
-
372
- return self.pool.apply_async(self.__call_api, (resource_path,
373
- method, path_params,
374
- query_params,
375
- header_params, body,
376
- post_params, files,
377
- response_type,
378
- auth_settings,
379
- _return_http_data_only,
380
- collection_formats,
381
- _preload_content,
382
- _request_timeout,
383
- _host))
384
-
385
- def request(self, method, url, query_params=None, headers=None,
386
- post_params=None, body=None, _preload_content=True,
387
- _request_timeout=None):
388
- """Makes the HTTP request using RESTClient."""
389
- if method == "GET":
390
- return self.rest_client.GET(url,
391
- query_params=query_params,
392
- _preload_content=_preload_content,
393
- _request_timeout=_request_timeout,
394
- headers=headers)
395
- elif method == "HEAD":
396
- return self.rest_client.HEAD(url,
397
- query_params=query_params,
398
- _preload_content=_preload_content,
399
- _request_timeout=_request_timeout,
400
- headers=headers)
401
- elif method == "OPTIONS":
402
- return self.rest_client.OPTIONS(url,
403
- query_params=query_params,
404
- headers=headers,
405
- _preload_content=_preload_content,
406
- _request_timeout=_request_timeout)
407
- elif method == "POST":
408
- return self.rest_client.POST(url,
409
- query_params=query_params,
410
- headers=headers,
411
- post_params=post_params,
412
- _preload_content=_preload_content,
413
- _request_timeout=_request_timeout,
414
- body=body)
415
- elif method == "PUT":
416
- return self.rest_client.PUT(url,
417
- query_params=query_params,
418
- headers=headers,
419
- post_params=post_params,
420
- _preload_content=_preload_content,
421
- _request_timeout=_request_timeout,
422
- body=body)
423
- elif method == "PATCH":
424
- return self.rest_client.PATCH(url,
425
- query_params=query_params,
426
- headers=headers,
427
- post_params=post_params,
428
- _preload_content=_preload_content,
429
- _request_timeout=_request_timeout,
430
- body=body)
431
- elif method == "DELETE":
432
- return self.rest_client.DELETE(url,
433
- query_params=query_params,
434
- headers=headers,
435
- _preload_content=_preload_content,
436
- _request_timeout=_request_timeout,
437
- body=body)
438
- else:
439
- raise ApiValueError(
440
- "http method must be `GET`, `HEAD`, `OPTIONS`,"
441
- " `POST`, `PATCH`, `PUT` or `DELETE`."
442
- )
443
-
444
- def parameters_to_tuples(self, params, collection_formats):
445
- """Get parameters as list of tuples, formatting collections.
446
-
447
- :param params: Parameters as dict or list of two-tuples
448
- :param dict collection_formats: Parameter collection formats
449
- :return: Parameters as list of tuples, collections formatted
450
- """
451
- new_params = []
452
- if collection_formats is None:
453
- collection_formats = {}
454
- for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501
455
- if k in collection_formats:
456
- collection_format = collection_formats[k]
457
- if collection_format == 'multi':
458
- new_params.extend((k, value) for value in v)
459
- else:
460
- if collection_format == 'ssv':
461
- delimiter = ' '
462
- elif collection_format == 'tsv':
463
- delimiter = '\t'
464
- elif collection_format == 'pipes':
465
- delimiter = '|'
466
- else: # csv is the default
467
- delimiter = ','
468
- new_params.append(
469
- (k, delimiter.join(str(value) for value in v)))
470
- else:
471
- new_params.append((k, v))
472
- return new_params
473
-
474
- def files_parameters(self, files=None):
475
- """Builds form parameters.
476
-
477
- :param files: File parameters.
478
- :return: Form parameters with files.
479
- """
480
- params = []
481
-
482
- if files:
483
- for k, v in six.iteritems(files):
484
- if not v:
485
- continue
486
- file_names = v if type(v) is list else [v]
487
- for n in file_names:
488
- with open(n, 'rb') as f:
489
- filename = os.path.basename(f.name)
490
- filedata = f.read()
491
- mimetype = (mimetypes.guess_type(filename)[0] or
492
- 'application/octet-stream')
493
- params.append(
494
- tuple([k, tuple([filename, filedata, mimetype])]))
495
-
496
- return params
497
-
498
- def select_header_accept(self, accepts):
499
- """Returns `Accept` based on an array of accepts provided.
500
-
501
- :param accepts: List of headers.
502
- :return: Accept (e.g. application/json).
503
- """
504
- if not accepts:
505
- return
506
-
507
- accepts = [x.lower() for x in accepts]
508
-
509
- if 'application/json' in accepts:
510
- return 'application/json'
511
- else:
512
- return ', '.join(accepts)
513
-
514
- def select_header_content_type(self, content_types):
515
- """Returns `Content-Type` based on an array of content_types provided.
516
-
517
- :param content_types: List of content-types.
518
- :return: Content-Type (e.g. application/json).
519
- """
520
- if not content_types:
521
- return 'application/json'
522
-
523
- content_types = [x.lower() for x in content_types]
524
-
525
- if 'application/json' in content_types or '*/*' in content_types:
526
- return 'application/json'
527
- else:
528
- return content_types[0]
529
-
530
- def update_params_for_auth(self, headers, querys, auth_settings):
531
- """Updates header and query params based on authentication setting.
532
-
533
- :param headers: Header parameters dict to be updated.
534
- :param querys: Query parameters tuple list to be updated.
535
- :param auth_settings: Authentication setting identifiers list.
536
- """
537
- if not auth_settings:
538
- return
539
-
540
- for auth in auth_settings:
541
- auth_setting = self.configuration.auth_settings().get(auth)
542
- if auth_setting:
543
- if auth_setting['in'] == 'cookie':
544
- headers['Cookie'] = auth_setting['value']
545
- elif auth_setting['in'] == 'header':
546
- headers[auth_setting['key']] = auth_setting['value']
547
- elif auth_setting['in'] == 'query':
548
- querys.append((auth_setting['key'], auth_setting['value']))
549
- else:
550
- raise ApiValueError(
551
- 'Authentication token must be in `query` or `header`'
552
- )
553
-
554
- def __deserialize_file(self, response):
555
- """Deserializes body to file
556
-
557
- Saves response body into a file in a temporary folder,
558
- using the filename from the `Content-Disposition` header if provided.
559
-
560
- :param response: RESTResponse.
561
- :return: file path.
562
- """
563
- fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
564
- os.close(fd)
565
- os.remove(path)
566
-
567
- content_disposition = response.getheader("Content-Disposition")
568
- if content_disposition:
569
- filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
570
- content_disposition).group(1)
571
- path = os.path.join(os.path.dirname(path), filename)
572
-
573
- with open(path, "wb") as f:
574
- f.write(response.data)
575
-
576
- return path
577
-
578
- def __deserialize_primitive(self, data, klass):
579
- """Deserializes string to primitive type.
580
-
581
- :param data: str.
582
- :param klass: class literal.
583
-
584
- :return: int, long, float, str, bool.
585
- """
586
- try:
587
- return klass(data)
588
- except UnicodeEncodeError:
589
- return six.text_type(data)
590
- except TypeError:
591
- return data
592
-
593
- def __deserialize_object(self, value):
594
- """Return an original value.
595
-
596
- :return: object.
597
- """
598
- return value
599
-
600
- def __deserialize_date(self, string):
601
- """Deserializes string to date.
602
-
603
- :param string: str.
604
- :return: date.
605
- """
606
- try:
607
- return parse(string).date()
608
- except ImportError:
609
- return string
610
- except ValueError:
611
- raise rest.ApiException(
612
- status=0,
613
- reason="Failed to parse `{0}` as date object".format(string)
614
- )
615
-
616
- def __deserialize_datetime(self, string):
617
- """Deserializes string to datetime.
618
-
619
- The string should be in iso8601 datetime format.
620
-
621
- :param string: str.
622
- :return: datetime.
623
- """
624
- try:
625
- return parse(string)
626
- except ImportError:
627
- return string
628
- except ValueError:
629
- raise rest.ApiException(
630
- status=0,
631
- reason=(
632
- "Failed to parse `{0}` as datetime object"
633
- .format(string)
634
- )
635
- )
636
-
637
- def __deserialize_model(self, data, klass):
638
- """Deserializes list or dict to model.
639
-
640
- :param data: dict, list.
641
- :param klass: class literal.
642
- :return: model object.
643
- """
644
- has_discriminator = False
645
- if (hasattr(klass, 'get_real_child_model')
646
- and klass.discriminator_value_class_map):
647
- has_discriminator = True
648
-
649
- if not klass.openapi_types and has_discriminator is False:
650
- return data
651
-
652
- kwargs = {}
653
- if (data is not None and
654
- klass.openapi_types is not None and
655
- isinstance(data, (list, dict))):
656
- for attr, attr_type in six.iteritems(klass.openapi_types):
657
- if klass.attribute_map[attr] in data:
658
- value = data[klass.attribute_map[attr]]
659
- kwargs[attr] = self.__deserialize(value, attr_type)
660
-
661
- instance = klass(**kwargs)
662
-
663
- if has_discriminator:
664
- klass_name = instance.get_real_child_model(data)
665
- if klass_name:
666
- instance = self.__deserialize(data, klass_name)
667
- return instance