From f7aba5114e2fc7595c1c819dae0778faa3ab30da Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Jan 2021 17:10:36 +0800 Subject: [PATCH] everything runs through now, only ordering missing --- etc/bin/mako-render | 4 ++++ src/mako/api/lib/mbuild.mako | 4 ++-- src/mako/api/lib/schema.mako | 6 +++--- src/mako/lib/cli.py | 2 +- src/mako/lib/util.py | 10 ++++++++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index b604c46b29..69d6ceddbc 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -188,6 +188,10 @@ class DictObject(object): """as dict.items""" return list(self.__dict__.items()) + def _items(self): + """as dict.items, avoiding name clashes""" + return list(self.__dict__.items()) + def pop(self, key, default=sys): """as dict.pop""" if default is sys: diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 2d30c99c29..79916b5da8 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -11,7 +11,7 @@ DELEGATE_PROPERTY_NAME, struct_type_bounds_s, scope_url_to_variant, re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE, method_name_to_variant, unique_type_name, size_to_bytes, method_default_scope, - is_repeated_property, setter_fn_name, ADD_SCOPE_FN, rust_doc_sanitize) + is_repeated_property, setter_fn_name, ADD_SCOPE_FN, rust_doc_sanitize, items) def get_parts(part_prop): if not part_prop: @@ -336,7 +336,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter} // into the respective structure. Some of the parts shown here might not be applicable ! // ${random_value_warning} let mut ${rb_name} = ${request_value_type}::default(); -% for spn, sp in request_value.get('properties', dict()).items(): +% for spn, sp in items(request_value.get('properties', dict())): % if parts is not None and spn not in parts: <% continue %> % endif diff --git a/src/mako/api/lib/schema.mako b/src/mako/api/lib/schema.mako index 5d9977248f..0f123af431 100644 --- a/src/mako/api/lib/schema.mako +++ b/src/mako/api/lib/schema.mako @@ -3,7 +3,7 @@ IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by, NESTED_TYPE_SUFFIX, RESPONSE_MARKER_TRAIT, split_camelcase_s, METHODS_RESOURCE, unique_type_name, PART_MARKER_TRAIT, canonical_type_name, TO_PARTS_MARKER, UNUSED_TYPE_MARKER, is_schema_with_optionals, - rust_doc_sanitize) + rust_doc_sanitize, items) %>\ ## Build a schema which must be an object ################################################################################################################### @@ -12,7 +12,7 @@ <% struct = 'pub struct ' + unique_type_name(s.id) %>\ % if properties: ${struct} { -% for pn, p in properties.items(): +% for pn, p in items(properties): ${p.get('description', 'no description provided') | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)} % if pn != mangle_ident(pn): #[serde(rename="${pn}")] @@ -111,7 +111,7 @@ impl ${TO_PARTS_MARKER} for ${s_type} { /// the parts you want to see in the server response. fn to_parts(&self) -> String { let mut r = String::new(); - % for pn, p in s.properties.items(): + % for pn, p in items(s.properties): <% mn = 'self.' + mangle_ident(pn) rt = to_rust_type(schemas, s.id, pn, p, allow_optionals=allow_optionals) diff --git a/src/mako/lib/cli.py b/src/mako/lib/cli.py index 71ba119ff0..5efc7689e3 100644 --- a/src/mako/lib/cli.py +++ b/src/mako/lib/cli.py @@ -172,7 +172,7 @@ def to_cli_schema(c, schema): properties[e.type_value] = e # end handle enumerations - for pn, p in properties.items(): + for pn, p in util.items(properties): def set_nested_schema(ns): if ns.fields: fd[pn] = ns diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index c005dcb4cd..503e504f79 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -114,6 +114,12 @@ data_unit_multipliers = { HUB_TYPE_PARAMETERS = ('C', 'A') +def items(p): + if isinstance(p, dict): + return p.items() + else: + return p._items() + # ============================================================================== ## @name Filters # ------------------------------------------------------------------------------ @@ -746,8 +752,8 @@ def new_context(schemas, resources, methods): # end this is already a perfectly valid type properties = s.get('properties', {'': s}) - print(properties) - for pn, p in properties.items(): + + for pn, p in items(properties): link_used(p, rs) if is_nested_type_property(p): ns = deepcopy(p)