ominfra 0.0.0.dev206__py3-none-any.whl → 0.0.0.dev208__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ import os.path
4
4
  import sys
5
5
  import typing as ta
6
6
 
7
+ from omlish import check
7
8
  from omlish import lang
8
9
  from omlish import marshal as msh
9
10
  from omlish.argparse import all as ap
@@ -30,14 +31,17 @@ class Cli(ap.Cli):
30
31
  ) -> str:
31
32
  service_model = ModelGen.load_service_model(service_name)
32
33
 
34
+ shape_names_seq = check.unique(shape_names or ())
35
+ operation_names_seq = check.unique(operation_names or ())
36
+
33
37
  bmg = ModelGen(
34
38
  service_model,
35
39
  shape_names=ModelGen.get_referenced_shape_names(
36
40
  service_model,
37
- shape_names=shape_names or (),
38
- operation_names=operation_names or (),
41
+ shape_names=shape_names_seq,
42
+ operation_names=operation_names_seq,
39
43
  ),
40
- operation_names=operation_names or (),
44
+ operation_names=operation_names_seq,
41
45
  )
42
46
 
43
47
  return bmg.gen_module()
@@ -6,6 +6,7 @@ TODO:
6
6
  import builtins
7
7
  import dataclasses as dc
8
8
  import io
9
+ import keyword
9
10
  import typing as ta
10
11
 
11
12
  from omlish import check
@@ -156,6 +157,7 @@ class ModelGen:
156
157
  'Boolean': 'bool',
157
158
 
158
159
  'Integer': 'int',
160
+ 'Long': 'int',
159
161
 
160
162
  'String': 'str',
161
163
 
@@ -181,7 +183,7 @@ class ModelGen:
181
183
  pass
182
184
 
183
185
  if name in self._shape_names:
184
- name = self.sanitize_class_name(name)
186
+ name = self.sanitize_global_name(name, upper=True)
185
187
  if not unquoted_names:
186
188
  return f"'{name}'"
187
189
  else:
@@ -248,10 +250,17 @@ class ModelGen:
248
250
 
249
251
  #
250
252
 
251
- def sanitize_class_name(self, n: str) -> str:
253
+ def sanitize_local_name(self, n: str) -> str:
254
+ if n in keyword.kwlist:
255
+ n += '_'
256
+ return n
257
+
258
+ def sanitize_global_name(self, n: str, *, upper: bool = False) -> str:
252
259
  if hasattr(builtins, n):
253
260
  n += '_'
254
- return n[0].upper() + n[1:]
261
+ if upper:
262
+ n = n[0].upper() + n[1:]
263
+ return n
255
264
 
256
265
  #
257
266
 
@@ -291,7 +300,7 @@ class ModelGen:
291
300
  ) -> ShapeSrc:
292
301
  shape: botocore.model.Shape = self._service_model.shape_for(name)
293
302
 
294
- san_name = self.sanitize_class_name(shape.name)
303
+ san_name = self.sanitize_global_name(shape.name, upper=True)
295
304
 
296
305
  if isinstance(shape, botocore.model.StructureShape):
297
306
  lines: list[str] = []
@@ -314,7 +323,7 @@ class ModelGen:
314
323
  for i, (mn, ms) in enumerate(shape.members.items()):
315
324
  if i:
316
325
  lines.append('')
317
- fn = self.demangle_name(mn)
326
+ fn = self.sanitize_local_name(self.demangle_name(mn))
318
327
  mds = [
319
328
  f'member_name={mn!r}',
320
329
  ]