|
4 | 4 |
|
5 | 5 | from .base import Code, CodeGenerator |
6 | 6 | from .jsonschema import build_default, build_data |
| 7 | +import six |
7 | 8 |
|
8 | 9 | SUPPORT_METHODS = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head'] |
9 | 10 |
|
@@ -109,8 +110,12 @@ def _type(parameters): |
109 | 110 | return url, params |
110 | 111 |
|
111 | 112 |
|
112 | | -def _remove_characters(text, deletechars): |
113 | | - return text.translate({ord(x): None for x in deletechars}) |
| 113 | +if six.PY3: |
| 114 | + def _remove_characters(text, deletechars): |
| 115 | + return text.translate({ord(x): None for x in deletechars}) |
| 116 | +else: |
| 117 | + def _remove_characters(text, deletechars): |
| 118 | + return text.translate(None, deletechars) |
114 | 119 |
|
115 | 120 |
|
116 | 121 | def _path_to_endpoint(swagger_path): |
@@ -150,18 +155,18 @@ def _dependence_callback(self, code): |
150 | 155 | # use sanic endpoint to replace default validator's key, |
151 | 156 | # example: `('some_path_param', 'method')` |
152 | 157 | validators = OrderedDict() |
153 | | - for k, v in schemas.data['validators'].items(): |
154 | | - locations = {_location(loc): val for loc, val in v.items()} |
| 158 | + for k, v in six.iteritems(schemas.data['validators']): |
| 159 | + locations = {_location(loc): val for loc, val in six.iteritems(v)} |
155 | 160 | validators[(_path_to_endpoint(k[0]), k[1])] = locations |
156 | 161 |
|
157 | 162 | # filters |
158 | 163 | filters = OrderedDict() |
159 | | - for k, v in schemas.data['filters'].items(): |
| 164 | + for k, v in six.iteritems(schemas.data['filters']): |
160 | 165 | filters[(_path_to_endpoint(k[0]), k[1])] = v |
161 | 166 |
|
162 | 167 | # scopes |
163 | 168 | scopes = OrderedDict() |
164 | | - for k, v in schemas.data['scopes'].items(): |
| 169 | + for k, v in six.iteritems(schemas.data['scopes']): |
165 | 170 | scopes[(_path_to_endpoint(k[0]), k[1])] = v |
166 | 171 |
|
167 | 172 | schemas.data['validators'] = validators |
@@ -191,7 +196,7 @@ def _process_data(self): |
191 | 196 | if validator: |
192 | 197 | methods[method]['requests'] = list(validator.keys()) |
193 | 198 |
|
194 | | - for status, res_data in data[method].get('responses', {}).items(): |
| 199 | + for status, res_data in six.iteritems(data[method].get('responses', {})): |
195 | 200 | if isinstance(status, int) or status.isdigit(): |
196 | 201 | example = res_data.get('examples', {}).get('application/json') |
197 | 202 |
|
|
0 commit comments