From 043f3752e67b3c08d3db162e37f95a3df3293609 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 23:24:57 +0800 Subject: [PATCH] basic python 3 port, nearly works --- etc/bin/mako-render | 4 ---- src/mako/api/lib.rs.mako | 2 +- src/mako/api/lib/lib.mako | 2 +- src/mako/api/lib/mbuild.mako | 6 +++--- src/mako/api/lib/rbuild.mako | 2 +- src/mako/api/lib/schema.mako | 6 +++--- src/mako/cli/lib/engine.mako | 2 +- src/mako/deps.mako | 2 +- src/mako/lib/cli.py | 2 +- src/mako/lib/util.py | 16 ++++++++-------- 10 files changed, 20 insertions(+), 24 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index 89c1a2fb56..6ade41757c 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -191,10 +191,6 @@ class DictObject(object): """as dict.items""" return list(self.__dict__.items()) - def iteritems(self): - """as dict.iteritems""" - return iter(self.__dict__.items()) - def pop(self, key, default=sys): """as dict.pop""" if default is sys: diff --git a/src/mako/api/lib.rs.mako b/src/mako/api/lib.rs.mako index 734433a757..c68bf3f5dc 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/mako/api/lib.rs.mako @@ -168,7 +168,7 @@ ${rbuild.new(resource, c)} // CallBuilders ### // ################# -% for resource, methods in c.rta_map.iteritems(): +% for resource, methods in c.rta_map.items(): % for method in methods: ${mbuild.new(resource, method, c)} diff --git a/src/mako/api/lib/lib.mako b/src/mako/api/lib/lib.mako index 94bc3d51dd..f3cca20bfe 100644 --- a/src/mako/api/lib/lib.mako +++ b/src/mako/api/lib/lib.mako @@ -156,7 +156,7 @@ let r = hub.resource().activity(...).${api.terms.action}() Or specifically ... ```ignore -% for an, a in c.sta_map[fr.id].iteritems(): +% for an, a in c.sta_map[fr.id].items(): <% category, resource, activity = activity_split(an) %>\ let r = hub.${mangle_ident(resource)}().${mangle_ident(activity)}(...).${api.terms.action}() % endfor diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 07d41532e5..2d30c99c29 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -154,7 +154,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ /// /// # Additional Parameters /// - % for opn, op in list((opn, op) for (opn, op) in parameters.iteritems() if opn not in [p.name for p in params]): + % for opn, op in list((opn, op) for (opn, op) in parameters.items() if opn not in [p.name for p in params]): /// * *${opn}* (${op.location}-${op.type}) - ${op.description} % endfor % endif @@ -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()).iteritems(): +% for spn, sp in request_value.get('properties', dict()).items(): % if parts is not None and spn not in parts: <% continue %> % endif @@ -896,7 +896,7 @@ if enable_resource_parsing \ % for p in media_params: ${p.description | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)} /// - % for item_name, item in p.info.iteritems(): + % for item_name, item in p.info.items(): /// * *${split_camelcase_s(item_name)}*: ${isinstance(item, (list, tuple)) and put_and(enclose_in("'", item)) or str(item)} % endfor pub fn ${upload_action_fn(api.terms.upload_action, p.type.suffix)}<${mtype_param}>(self, ${p.type.arg_name}: ${mtype_param}, mime_type: mime::Mime) -> ${rtype} diff --git a/src/mako/api/lib/rbuild.mako b/src/mako/api/lib/rbuild.mako index f87d3378ae..feff10e5c8 100644 --- a/src/mako/api/lib/rbuild.mako +++ b/src/mako/api/lib/rbuild.mako @@ -110,7 +110,7 @@ impl${rb_params} ${ThisType} { % for p in optional_props: ${property(p.name)}: Default::default(), % endfor -% for prop_key, custom_name in api.properties.iteritems(): +% for prop_key, custom_name in api.properties.items(): % if prop_key == 'scopes' and not method_default_scope(m): <% continue %>\ % endif diff --git a/src/mako/api/lib/schema.mako b/src/mako/api/lib/schema.mako index 0484b5c40b..5d9977248f 100644 --- a/src/mako/api/lib/schema.mako +++ b/src/mako/api/lib/schema.mako @@ -12,7 +12,7 @@ <% struct = 'pub struct ' + unique_type_name(s.id) %>\ % if properties: ${struct} { -% for pn, p in properties.iteritems(): +% for pn, p in properties.items(): ${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.iteritems(): + % for pn, p in s.properties.items(): <% mn = 'self.' + mangle_ident(pn) rt = to_rust_type(schemas, s.id, pn, p, allow_optionals=allow_optionals) @@ -140,7 +140,7 @@ ${s.get('description', 'There is no detailed description.')} This type is used in activities, which are methods you may call on this type or where this type is involved in. The list links the activity name, along with information about where it is used (one of ${put_and(enclose_in('*', IO_TYPES))}). -% for a, iot in c.sta_map[s.id].iteritems(): +% for a, iot in c.sta_map[s.id].items(): <% category, name, method = activity_split(a) name_suffix = ' ' + split_camelcase_s(name) diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index 6319331f78..193a9b30e1 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -357,7 +357,7 @@ if dry_run { allow_optionals = allow_optionals_fn(schema) if not allow_optionals: opt_access = '' - for fn, f in schema.fields.iteritems(): + for fn, f in schema.fields.items(): cur.append(['%s%s' % (mangle_ident(fn), opt_access), fn]) fields.add(fn) if isinstance(f, SchemaEntry): diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 38811c3117..d53bc7a73b 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -46,7 +46,7 @@ if mako is not UNDEFINED: post_processor_arg = '--post-process-python-module=%s' % mako.post_processor_module %>\ -% for an, versions in api.list.iteritems(): +% for an, versions in api.list.items(): % if an in api.get('blacklist', list()): <% continue %>\ % endif diff --git a/src/mako/lib/cli.py b/src/mako/lib/cli.py index 3c73494b93..71ba119ff0 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.iteritems(): + for pn, p in properties.items(): 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 b4e7c15d9f..b9b4b49552 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -440,7 +440,7 @@ def schema_markers(s, c, transitive=True): continue has_activity = True # it should have at least one activity that matches it's type to qualify for the Resource trait - for fqan, iot in activities.iteritems(): + for fqan, iot in activities.items(): _, resource, _ = activity_split(fqan) if resource and activity_name_to_type_name(resource).lower() == sid.lower(): res.add(RESOURCE_MARKER_TRAIT) @@ -504,7 +504,7 @@ def activity_name_to_type_name(an): # yields (category, resource, activity, activity_data) def iter_acitivities(c): - return ((activity_split(an) + [a]) for an, a in c.fqan_map.iteritems()) + return ((activity_split(an) + [a]) for an, a in c.fqan_map.items()) # return a list of parameter structures of all params of the given method dict # apply a prune filter to restrict the set of returned parameters. @@ -512,7 +512,7 @@ def iter_acitivities(c): def _method_params(m, required=None, location=None): res = list() po = m.get('parameterOrder', []) - for pn, p in m.get('parameters', dict()).iteritems(): + for pn, p in m.get('parameters', dict()).items(): if required is not None and p.get('required', False) != required: continue if location is not None and p.get('location', '') != location: @@ -613,7 +613,7 @@ def method_media_params(m): # actually, one of them is required, but we can't encode that ... # runtime will have to check res = list() - for pn, proto in mu.protocols.iteritems(): + for pn, proto in mu.protocols.items(): # the pi (proto-info) dict can be shown to the user pi = {'multipart': proto.multipart and 'yes' or 'no', 'maxSize': mu.get('maxSize', '0kb'), 'validMimeTypes': mu.accept} try: @@ -672,12 +672,12 @@ def new_context(schemas, resources, methods): res = dict() if fqan is None: fqan = dict() - for k,a in activities.iteritems(): + for k,a in activities.items(): if 'resources' in a: build_activity_mappings(a.resources, res, fqan) if 'methods' not in a: continue - for mn, m in a.methods.iteritems(): + for mn, m in a.methods.items(): assert m.id not in fqan category, resource, method = activity_split(m.id) # This may be another name by which people try to find the method. @@ -746,7 +746,7 @@ def new_context(schemas, resources, methods): # end this is already a perfectly valid type properties = s.get('properties', {'': s}) - for pn, p in properties.iteritems(): + for pn, p in properties.items(): link_used(p, rs) if is_nested_type_property(p): ns = deepcopy(p) @@ -755,7 +755,7 @@ def new_context(schemas, resources, methods): # To allow us recursing arrays, we simply put items one level up if 'items' in p: - ns.update((k, deepcopy(v)) for k, v in p.items.iteritems()) + ns.update((k, deepcopy(v)) for k, v in p.items.items()) recurse_properties(ns.id, ns, ns, append_unique(parent_ids, rs.id)) elif is_map_prop(p):