From 33e85ddd29db5a75ce49718d850652c36ad7ce25 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 17 Mar 2015 10:39:11 +0100 Subject: [PATCH] feat(doit): set upload media type Related to #17 --- src/mako/lib/mbuild.mako | 18 ++++++++++++++++++ src/mako/lib/util.py | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 79b1df67b7..74e2ec8b08 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -454,6 +454,24 @@ else { self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_slice().to_string(), ()); } % endif + ## Only one of them is going to be set, even though we generate code that doesn't care + % if media_params: + { + let protocol =\ + % for mp in media_params: + % if loop.first: + if \ + % else: + else if \ + % endif +${mp.type.arg_name}.is_some() { + "${mp.protocol}" + }\ + % endfor + else { unreachable!() }; + params.push(("uploadType", protocol.to_string())); + } + % endif url.push('?'); url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 0d774b5f6a..39d1ff4923 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -10,6 +10,10 @@ re_linestart = re.compile('^', flags=re.MULTILINE) re_first_4_spaces = re.compile('^ {1,4}', flags=re.MULTILINE) re_desc_parts = re.compile("((the part (names|properties) that you can include in the parameter value are)|(supported values are ))(.*?)\.", flags=re.IGNORECASE|re.MULTILINE) +re_find_replacements = re.compile("\{\w+\}") + + + USE_FORMAT = 'use_format_field' TYPE_MAP = {'boolean' : 'bool', 'integer' : USE_FORMAT, @@ -524,7 +528,8 @@ def method_media_params(m): except KeyError: raise AssertionError("media upload protocol '%s' is not implemented" % pn) p = type(m)({'name': 'media_%s', - 'info': pi, + 'info': pi, + 'protocol': pn, 'path': proto.path, 'type': ti, 'description': ti.description,