Skip to content

Commit 4e44b67

Browse files
authored
Merge pull request KscSDK#6 from wcg49802693/master
需求的完成和配置文件错误的修改
2 parents 0af8a3a + 9b01adb commit 4e44b67

File tree

5 files changed

+82
-9
lines changed

5 files changed

+82
-9
lines changed

kscore/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,21 @@ def _convert_to_request_dict(self, api_params, operation_model,
557557
operation_name=operation_name),
558558
params=api_params, model=operation_model, context=context)
559559

560-
request_dict = self._serializer.serialize_to_request(
561-
api_params, operation_model)
560+
operation_protocol_serialize = None
561+
if operation_model._operation_model.has_key('protocol'):
562+
operation_protocol = operation_model._operation_model['protocol']
563+
if operation_protocol is not None:
564+
operation_protocol_serialize = kscore.serialize.create_serializer(
565+
operation_protocol, True)
566+
567+
if operation_protocol_serialize is not None:
568+
request_dict = operation_protocol_serialize.serialize_to_request(
569+
api_params, operation_model
570+
)
571+
else:
572+
request_dict = self._serializer.serialize_to_request(
573+
api_params, operation_model)
574+
562575
prepare_request_dict(request_dict, endpoint_url=self._endpoint.host,
563576
user_agent=self._client_config.user_agent)
564577
return request_dict

kscore/data/kog/2016-05-13/service-2.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ shapes:
888888
key:
889889
shape: NonEmptyString
890890
value:
891-
shape: NonEmptyString
891+
shape: Id
892892

893893
# [{'a': 'xxxx'}, {'b': 'xxxx'}]
894894
Maps:
@@ -1826,6 +1826,17 @@ shapes:
18261826
documentation: ""
18271827

18281828
# ======== 批量删除变量的参数配置 ========
1829+
BatchDelVbMaps:
1830+
type: list
1831+
member:
1832+
shape: BatchDelVbMap
1833+
1834+
BatchDelVbMap:
1835+
type: map
1836+
key:
1837+
shape: NonEmptyString
1838+
value:
1839+
shape: NonEmptyString
18291840

18301841
BatchDeleteVariable:
18311842
type: structure
@@ -1837,7 +1848,7 @@ shapes:
18371848
shape: Id
18381849
documentation: ""
18391850
varList:
1840-
shape: Maps
1851+
shape: BatchDelVbMaps
18411852
documentation: ""
18421853
documentation: ""
18431854

kscore/endpoint.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,14 @@ def _get_response(self, request, operation_model, attempts):
197197
# This returns the http_response and the parsed_data.
198198
response_dict = convert_to_response_dict(http_response,
199199
operation_model)
200-
parser = self._response_parser_factory.create_parser(
201-
operation_model.metadata['protocol'])
200+
201+
protocol = operation_model.metadata['protocol']
202+
if operation_model._operation_model.has_key('protocol'):
203+
operation_protocol = operation_model._operation_model['protocol']
204+
if operation_protocol is not None:
205+
protocol = operation_protocol
206+
parser = self._response_parser_factory.create_parser(protocol)
207+
202208
return ((http_response,
203209
parser.parse(response_dict, operation_model.output_shape)),
204210
None)

kscore/parsers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ def _parse_error_from_body(self, response):
784784
'query': QueryParser,
785785
'query-json': JSONParser,
786786
'kcs': JSONParser,
787+
'custom-body': JSONParser,
787788
'json': JSONParser,
788789
'json2': JSONParser,
789790
'rest-json': RestJSONParser,

kscore/serialize.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,12 @@ def serialize_to_request(self, parameters, operation_model):
194194
'X-Version': operation_model.metadata['apiVersion'],
195195
}
196196
)
197-
body_params = {}
197+
body_params = self.MAP_TYPE()
198198

199199
if shape is not None:
200200
self._serialize(body_params, parameters, shape)
201201
else:
202202
self._serialize_not_shape(body_params, parameters)
203-
204203
return self._serialize_data(serialized, body_params)
205204

206205
def _serialize_not_shape(self, data, parameters):
@@ -349,6 +348,48 @@ def _serialize_data(self, serialized, data):
349348
return serialized
350349

351350

351+
class CustomBodySerializer(QuerySerializer):
352+
353+
@property
354+
def headers(self):
355+
return {"Accept": 'application/json'}
356+
357+
def _serialize_not_shape(self, data, parameters):
358+
359+
data.update(parameters)
360+
361+
def serialize_to_request(self, parameters, operation_model):
362+
shape = operation_model.input_shape
363+
serialized = self._create_default_request()
364+
serialized['method'] = operation_model.http.get('method',
365+
self.DEFAULT_METHOD)
366+
# The query serializer only deals with body params so
367+
# that's what we hand off the _serialize_* methods.
368+
serialized['headers'].update(
369+
{
370+
'X-Action': operation_model.name,
371+
'X-Version': operation_model.metadata['apiVersion'],
372+
}
373+
)
374+
body_params = self.MAP_TYPE()
375+
if 'Body' in parameters:
376+
body_params['Body'] = parameters['Body']
377+
del parameters['Body']
378+
379+
if shape is not None:
380+
self._serialize(body_params, parameters, shape)
381+
else:
382+
self._serialize_not_shape(body_params, parameters)
383+
return self._serialize_data(serialized, body_params)
384+
385+
def _serialize_data(self, serialized, data):
386+
serialized['body'] = json.dumps(data).encode(self.DEFAULT_ENCODING)
387+
if 'Body' in data:
388+
del data['Body']
389+
serialized['query_string'] = data
390+
return serialized
391+
392+
352393
class JSONSerializer(Serializer):
353394
"""
354395
BASE JSON REQUEST all method with json body
@@ -371,7 +412,7 @@ def serialize_to_request(self, parameters, operation_model):
371412
'X-Action': operation_model.name,
372413
'X-Version': operation_model.metadata['apiVersion']
373414
}
374-
body = {}
415+
body = self.MAP_TYPE()
375416
input_shape = operation_model.input_shape
376417
if input_shape is not None:
377418
self._serialize(body, parameters, input_shape)
@@ -718,4 +759,5 @@ def _default_serialize(self, xmlnode, params, shape, name):
718759
'json2': NotGetJsonSerializer,
719760
'rest-json': RestJSONSerializer,
720761
'rest-xml': RestXMLSerializer,
762+
'custom-body': CustomBodySerializer,
721763
}

0 commit comments

Comments
 (0)