simpler arg parsing

This commit is contained in:
Honza Král
2019-12-22 16:32:49 +01:00
committed by Honza Král
parent b6cb75f46a
commit b4e6effc9c
3 changed files with 10 additions and 9 deletions
+6 -5
View File
@@ -159,7 +159,7 @@ class API:
parts = self.all_parts
return chain(
((p, parts[p]) for p in parts if parts[p]["required"]),
self.body.items() if self.body["body"] else (),
(("body", self.body), ) if self.body else (),
((p, parts[p]) for p in parts if not parts[p]["required"]),
sorted(self._def.get("params", {}).items()),
)
@@ -169,7 +169,7 @@ class API:
b = self._def.get("body", {})
if b:
b.setdefault("required", False)
return {"body": b}
return b
@property
def query_params(self):
@@ -214,9 +214,10 @@ class API:
@property
def required_parts(self):
parts = self.all_parts
return [p for p in parts if parts[p]["required"]] + [
b for b in self.body if self.body[b].get("required")
]
required = [p for p in parts if parts[p]["required"]]
if self.body.get("required"):
required.append("body")
return required
def to_python(self):
try:
+2 -2
View File
@@ -20,10 +20,10 @@
"""
{% include "substitutions" %}
{% include "required" %}
{% if api.body.body.serialize == "bulk" %}
{% if api.body.serialize == "bulk" %}
body = self._bulk_body(body)
{% endif %}
{% block request %}
return self.transport.perform_request("{{ api.method }}", {% include "url" %}, params=params{% if api.body.body %}, body=body{% endif %})
return self.transport.perform_request("{{ api.method }}", {% include "url" %}, params=params{% if api.body %}, body=body{% endif %})
{% endblock %}
+2 -2
View File
@@ -2,8 +2,8 @@
{% if info.required %}{{ p }}, {% endif %}
{% endfor %}
{% if api.body.body %}
body{% if not api.body.body.required %}=None{% endif %},
{% if api.body %}
body{% if not api.body.required %}=None{% endif %},
{% endif %}
{% for p, info in api.all_parts.items() %}