From efe56ad25081b632f1e65fd8292e9c4d535659bc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 11 Mar 2015 08:40:05 +0100 Subject: [PATCH] fix(util): deepcopy dicts instead It was possible for writes to happen in nested dicts, causing global data to change and confuse the system. Not that I wouldn't be aware of that danger, but apparently I didn't see the recursiveness of the call tree :). --- src/mako/lib/schema.mako | 6 +++--- src/mako/lib/util.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mako/lib/schema.mako b/src/mako/lib/schema.mako index fd76e38e10..8d9a444ce3 100644 --- a/src/mako/lib/schema.mako +++ b/src/mako/lib/schema.mako @@ -1,5 +1,5 @@ <%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and, - IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type) + IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by) %>\ ## Create new schema with everything. ## 's' contains the schema structure from json to build @@ -7,7 +7,7 @@ ################################################################################################################### <%def name="new(s, c)">\ <% - ## assert s.type == "object" + assert s.type == "object" markers = schema_markers(s, c) %>\ <%block filter="rust_doc_comment">\ @@ -18,7 +18,7 @@ pub struct ${s.id}\ % if 'properties' in s: { % for pn, p in s.properties.iteritems(): - ${p.get('description', 'no description provided') | rust_doc_comment} + ${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)} pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)}, % endfor } diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index cebeae7348..1144af15ed 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -2,6 +2,7 @@ import re import os from random import (randint, random, choice, seed) import collections +from copy import deepcopy seed(1337) @@ -271,7 +272,6 @@ def to_rust_type(sn, pn, t, allow_optionals=True): else: assert(is_nested_type_property(nt)) # It's a nested type - we take it literally like $ref, but generate a name for the type ourselves - # This of course assumes return nested_type_name(sn, pn) return to_rust_type(sn, pn, nt, allow_optionals=False) @@ -331,7 +331,7 @@ def iter_nested_types(schemas): def iter_nested_properties(prefix, properties): for pn, p in properties.iteritems(): if is_nested_type_property(p): - ns = p.copy() + ns = deepcopy(p) ns.id = nested_type_name(prefix, pn) ns[NESTED_TYPE_MARKER] = True if 'items' in p: @@ -410,7 +410,7 @@ def method_params(m, required=None, location=None): continue if location is not None and p.get('location', '') != location: continue - np = p.copy() + np = deepcopy(p) np['name'] = pn try: # po = ['part', 'foo']