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 parts = self.all_parts
return chain( return chain(
((p, parts[p]) for p in parts if parts[p]["required"]), ((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"]), ((p, parts[p]) for p in parts if not parts[p]["required"]),
sorted(self._def.get("params", {}).items()), sorted(self._def.get("params", {}).items()),
) )
@@ -169,7 +169,7 @@ class API:
b = self._def.get("body", {}) b = self._def.get("body", {})
if b: if b:
b.setdefault("required", False) b.setdefault("required", False)
return {"body": b} return b
@property @property
def query_params(self): def query_params(self):
@@ -214,9 +214,10 @@ class API:
@property @property
def required_parts(self): def required_parts(self):
parts = self.all_parts parts = self.all_parts
return [p for p in parts if parts[p]["required"]] + [ required = [p for p in parts if parts[p]["required"]]
b for b in self.body if self.body[b].get("required") if self.body.get("required"):
] required.append("body")
return required
def to_python(self): def to_python(self):
try: try:
+2 -2
View File
@@ -20,10 +20,10 @@
""" """
{% include "substitutions" %} {% include "substitutions" %}
{% include "required" %} {% include "required" %}
{% if api.body.body.serialize == "bulk" %} {% if api.body.serialize == "bulk" %}
body = self._bulk_body(body) body = self._bulk_body(body)
{% endif %} {% endif %}
{% block request %} {% 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 %} {% endblock %}
+2 -2
View File
@@ -2,8 +2,8 @@
{% if info.required %}{{ p }}, {% endif %} {% if info.required %}{{ p }}, {% endif %}
{% endfor %} {% endfor %}
{% if api.body.body %} {% if api.body %}
body{% if not api.body.body.required %}=None{% endif %}, body{% if not api.body.required %}=None{% endif %},
{% endif %} {% endif %}
{% for p, info in api.all_parts.items() %} {% for p, info in api.all_parts.items() %}