From 9f248338ff03bb77b5678b43100418475b6c13da Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Fri, 1 Jun 2012 18:04:25 +0200 Subject: [PATCH] Refactor switches in templates: step 2 --- .../GithubObject.MethodBody.CheckResult.py | 3 ++ .../GithubObject.MethodBody.ReturnValue.py | 12 ++++++ .../GithubObject.MethodBody.UseResult.py | 39 +------------------ .../templates/GithubObject.PublicMethods.py | 1 + 4 files changed, 18 insertions(+), 37 deletions(-) create mode 100644 codegen/templates/GithubObject.MethodBody.CheckResult.py create mode 100644 codegen/templates/GithubObject.MethodBody.ReturnValue.py diff --git a/codegen/templates/GithubObject.MethodBody.CheckResult.py b/codegen/templates/GithubObject.MethodBody.CheckResult.py new file mode 100644 index 00000000..bd83db47 --- /dev/null +++ b/codegen/templates/GithubObject.MethodBody.CheckResult.py @@ -0,0 +1,3 @@ +{% if method.type.name != "bool" %} + self._checkStatus( status, data ) +{% endif %} diff --git a/codegen/templates/GithubObject.MethodBody.ReturnValue.py b/codegen/templates/GithubObject.MethodBody.ReturnValue.py new file mode 100644 index 00000000..f51c09ad --- /dev/null +++ b/codegen/templates/GithubObject.MethodBody.ReturnValue.py @@ -0,0 +1,12 @@ +{% if method.type.name == "bool" %}status == 204 +{% else %}{% if method.type.simple %}data +{% else %}{% if method.type.cardinality == "scalar" %}{% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self._requester, data, completed = True ) +{% else %}PaginatedList.PaginatedList( + {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}, + self._requester, + headers, + data + ) +{% endif %} +{% endif %} +{% endif %} diff --git a/codegen/templates/GithubObject.MethodBody.UseResult.py b/codegen/templates/GithubObject.MethodBody.UseResult.py index cff2ffa8..0cbc0959 100644 --- a/codegen/templates/GithubObject.MethodBody.UseResult.py +++ b/codegen/templates/GithubObject.MethodBody.UseResult.py @@ -1,42 +1,7 @@ -{% if method.type.name != "bool" %} - self._checkStatus( status, data ) -{% endif %} - {% if method.isMutation %} self._useAttributes( data ) -{% endif %} - -{% if method.type.simple %} - - {% if method.type.cardinality == "scalar" %} - - {% if method.type.name == "bool" %} - return status == 204 - {% endif %} - - {% if method.type.name == "@todo" %} - return data - {% endif %} - - {% endif %} - - {% if method.type.cardinality == "list" or method.type.cardinality == "dict" %} - return data - {% endif %} - {% else %} - - {% if method.type.cardinality == "scalar" %} - return {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self._requester, data, completed = True ) + {% if method.type.name != "void" %} + return {% include "GithubObject.MethodBody.ReturnValue.py" %} {% endif %} - - {% if method.type.cardinality == "list" %} - return PaginatedList.PaginatedList( - {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}, - self._requester, - headers, - data - ) - {% endif %} - {% endif %} diff --git a/codegen/templates/GithubObject.PublicMethods.py b/codegen/templates/GithubObject.PublicMethods.py index 1b4297b4..48171d5d 100644 --- a/codegen/templates/GithubObject.PublicMethods.py +++ b/codegen/templates/GithubObject.PublicMethods.py @@ -2,5 +2,6 @@ def {{ method.name|join:"_" }}( {% include "GithubObject.Parameters.py" with function=method only %} ): {% include "GithubObject.MethodBody.CheckArguments.py" %} {% include "GithubObject.MethodBody.DoRequest.py" %} + {% include "GithubObject.MethodBody.CheckResult.py" %} {% include "GithubObject.MethodBody.UseResult.py" %} {% endfor %}