From ca390879f0e9748ce9f4347fb369f92cdde349ca Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 31 May 2012 21:53:27 +0100 Subject: [PATCH] Refactor switches in templates: step 1 --- ...ithubObject.AttributeValue.complex.dict.py | 4 + ...ithubObject.AttributeValue.complex.list.py | 4 + .../GithubObject.AttributeValue.complex.py | 1 + ...hubObject.AttributeValue.complex.scalar.py | 1 + .../GithubObject.AttributeValue.simple.py | 1 + .../GithubObject.Concatenation.argument.py | 1 + .../GithubObject.Concatenation.attribute.py | 1 + .../GithubObject.Concatenation.constant.py | 1 + .../GithubObject.Concatenation.identity.py | 1 + .../GithubObject.Concatenation.parentUrl.py | 1 + .../templates/GithubObject.Concatenation.py | 2 +- .../GithubObject.Concatenation.urlquote.py | 1 + .../templates/GithubObject.Implementation.py | 109 +++++----------- .../templates/GithubObject.IsInstance.bool.py | 1 + ...bObject.IsInstance.dict.complex_as_dict.py | 1 + .../templates/GithubObject.IsInstance.dict.py | 1 + .../GithubObject.IsInstance.integer.py | 1 + .../GithubObject.IsInstance.list.complex.py | 1 + ...bObject.IsInstance.list.complex_as_dict.py | 1 + .../GithubObject.IsInstance.list.simple.py | 1 + codegen/templates/GithubObject.IsInstance.py | 1 + .../GithubObject.IsInstance.scalar.complex.py | 1 + ...bject.IsInstance.scalar.complex_as_dict.py | 1 + .../GithubObject.IsInstance.scalar.simple.py | 1 + .../GithubObject.IsInstance.string.py | 1 + .../GithubObject.MethodBody.CheckArguments.py | 121 ++++-------------- .../GithubObject.PublicAttributes.py | 16 +-- .../templates/GithubObject.PublicMethods.py | 12 +- src/github/AuthenticatedUser.py | 4 +- src/github/Authorization.py | 2 +- src/github/Commit.py | 8 +- src/github/Comparison.py | 8 +- src/github/Gist.py | 11 +- src/github/GitCommit.py | 4 +- src/github/GitTree.py | 4 +- src/github/Hook.py | 2 +- src/github/Issue.py | 8 +- 37 files changed, 126 insertions(+), 214 deletions(-) create mode 100644 codegen/templates/GithubObject.AttributeValue.complex.dict.py create mode 100644 codegen/templates/GithubObject.AttributeValue.complex.list.py create mode 100644 codegen/templates/GithubObject.AttributeValue.complex.py create mode 100644 codegen/templates/GithubObject.AttributeValue.complex.scalar.py create mode 100644 codegen/templates/GithubObject.AttributeValue.simple.py create mode 100644 codegen/templates/GithubObject.Concatenation.argument.py create mode 100644 codegen/templates/GithubObject.Concatenation.attribute.py create mode 100644 codegen/templates/GithubObject.Concatenation.constant.py create mode 100644 codegen/templates/GithubObject.Concatenation.identity.py create mode 100644 codegen/templates/GithubObject.Concatenation.parentUrl.py create mode 100644 codegen/templates/GithubObject.Concatenation.urlquote.py create mode 100644 codegen/templates/GithubObject.IsInstance.bool.py create mode 100644 codegen/templates/GithubObject.IsInstance.dict.complex_as_dict.py create mode 100644 codegen/templates/GithubObject.IsInstance.dict.py create mode 100644 codegen/templates/GithubObject.IsInstance.integer.py create mode 100644 codegen/templates/GithubObject.IsInstance.list.complex.py create mode 100644 codegen/templates/GithubObject.IsInstance.list.complex_as_dict.py create mode 100644 codegen/templates/GithubObject.IsInstance.list.simple.py create mode 100644 codegen/templates/GithubObject.IsInstance.py create mode 100644 codegen/templates/GithubObject.IsInstance.scalar.complex.py create mode 100644 codegen/templates/GithubObject.IsInstance.scalar.complex_as_dict.py create mode 100644 codegen/templates/GithubObject.IsInstance.scalar.simple.py create mode 100644 codegen/templates/GithubObject.IsInstance.string.py diff --git a/codegen/templates/GithubObject.AttributeValue.complex.dict.py b/codegen/templates/GithubObject.AttributeValue.complex.dict.py new file mode 100644 index 00000000..f0992386 --- /dev/null +++ b/codegen/templates/GithubObject.AttributeValue.complex.dict.py @@ -0,0 +1,4 @@ +{ + key : {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) + for key, element in attributes[ "{{ attribute.name }}" ].iteritems() + } \ No newline at end of file diff --git a/codegen/templates/GithubObject.AttributeValue.complex.list.py b/codegen/templates/GithubObject.AttributeValue.complex.list.py new file mode 100644 index 00000000..082088da --- /dev/null +++ b/codegen/templates/GithubObject.AttributeValue.complex.list.py @@ -0,0 +1,4 @@ +[ + {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) + for element in attributes[ "{{ attribute.name }}" ] + ] \ No newline at end of file diff --git a/codegen/templates/GithubObject.AttributeValue.complex.py b/codegen/templates/GithubObject.AttributeValue.complex.py new file mode 100644 index 00000000..681143ce --- /dev/null +++ b/codegen/templates/GithubObject.AttributeValue.complex.py @@ -0,0 +1 @@ +{% with template_name="GithubObject.AttributeValue.complex."|add:attribute.type.cardinality|add:".py" %}None if attributes[ "{{ attribute.name }}" ] is None else {% include template_name %}{% endwith %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.AttributeValue.complex.scalar.py b/codegen/templates/GithubObject.AttributeValue.complex.scalar.py new file mode 100644 index 00000000..77977cef --- /dev/null +++ b/codegen/templates/GithubObject.AttributeValue.complex.scalar.py @@ -0,0 +1 @@ +{% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, attributes[ "{{ attribute.name }}" ], completed = False ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.AttributeValue.simple.py b/codegen/templates/GithubObject.AttributeValue.simple.py new file mode 100644 index 00000000..3a709457 --- /dev/null +++ b/codegen/templates/GithubObject.AttributeValue.simple.py @@ -0,0 +1 @@ +attributes[ "{{ attribute.name }}" ] \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.argument.py b/codegen/templates/GithubObject.Concatenation.argument.py new file mode 100644 index 00000000..c2a2d8b8 --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.argument.py @@ -0,0 +1 @@ +str( {{ value|join:"." }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.attribute.py b/codegen/templates/GithubObject.Concatenation.attribute.py new file mode 100644 index 00000000..50c2585f --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.attribute.py @@ -0,0 +1 @@ +str( self.{{ value|join:"." }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.constant.py b/codegen/templates/GithubObject.Concatenation.constant.py new file mode 100644 index 00000000..62eb8246 --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.constant.py @@ -0,0 +1 @@ +"{{ value }}" \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.identity.py b/codegen/templates/GithubObject.Concatenation.identity.py new file mode 100644 index 00000000..c05ab3d5 --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.identity.py @@ -0,0 +1 @@ +str( {{ value|join:"." }}._identity ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.parentUrl.py b/codegen/templates/GithubObject.Concatenation.parentUrl.py new file mode 100644 index 00000000..67ac3a25 --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.parentUrl.py @@ -0,0 +1 @@ +self._parentUrl( {% include "GithubObject.Concatenation.py" with concatenation=value only %} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.py b/codegen/templates/GithubObject.Concatenation.py index 689c1e5b..1c7716c8 100644 --- a/codegen/templates/GithubObject.Concatenation.py +++ b/codegen/templates/GithubObject.Concatenation.py @@ -1 +1 @@ -{% for part in concatenation %}{% if forloop.counter0 > 0 %} + {% endif %}{% if part.type == "constant" %}"{{ part.value }}"{% endif %}{% if part.type == "argument" %}str( {{ part.value|join:"." }} ){% endif %}{% if part.type == "attribute" %}str( self.{{ part.value|join:"." }} ){% endif %}{% if part.type == "urlquote" %}urllib.quote( {% with template_name="GithubObject.Concatenation.py" %}{% include template_name with concatenation=part.value only %}{% endwith %} ){% endif %}{% if part.type == "parentUrl" %}self._parentUrl( {% with template_name="GithubObject.Concatenation.py" %}{% include template_name with concatenation=part.value only %}{% endwith %} ){% endif %}{% if part.type == "identity" %}str( {{ part.value|join:"." }}._identity ){% endif %}{% endfor %} \ No newline at end of file +{% for part in concatenation %}{% if forloop.counter0 > 0 %} + {% endif %}{% with part_template_name="GithubObject.Concatenation."|add:part.type|add:".py" %}{% include part_template_name with value=part.value only %}{% endwith %}{% endfor %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.Concatenation.urlquote.py b/codegen/templates/GithubObject.Concatenation.urlquote.py new file mode 100644 index 00000000..d42785e5 --- /dev/null +++ b/codegen/templates/GithubObject.Concatenation.urlquote.py @@ -0,0 +1 @@ +urllib.quote( {% include "GithubObject.Concatenation.py" with concatenation=value only %} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.Implementation.py b/codegen/templates/GithubObject.Implementation.py index f7c132ff..679b231a 100644 --- a/codegen/templates/GithubObject.Implementation.py +++ b/codegen/templates/GithubObject.Implementation.py @@ -1,81 +1,30 @@ -{% if class.identity %} - @property - def _identity( self ): - return {% include "GithubObject.Concatenation.py" with concatenation=class.identity only %} -{% endif %} +{% if class.identity %} + @property + def _identity( self ): + return {% include "GithubObject.Concatenation.py" with concatenation=class.identity only %} +{% endif %} + + def _initAttributes( self ): +{% for attribute in class.attributes|dictsort:"name" %} + self._{{ attribute.name }} = GithubObject.NotSet +{% endfor %} + + def _useAttributes( self, attributes ): +{% for attribute in class.attributes|dictsort:"name" %} - def _initAttributes( self ): -{% for attribute in class.attributes|dictsort:"name" %} - self._{{ attribute.name }} = GithubObject.NotSet -{% endfor %} - - def _useAttributes( self, attributes ): -{% for attribute in class.attributes|dictsort:"name" %} - if "{{ attribute.name }}" in attributes: # pragma no branch - -{% if attribute.type.cardinality == "scalar" %} - {% if attribute.type.simple %} - {% if attribute.type.name == "string" %} - assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], ( str, unicode ) ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% if attribute.type.name == "integer" %} - assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], int ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% if attribute.type.name == "bool" %} - assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], bool ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% if attribute.type.name == "dict" %} - assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], dict ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% else %} - assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], dict ), attributes[ "{{ attribute.name }}" ] - {% endif %} -{% endif %} - -{% if attribute.type.cardinality == "list" %} - {% if attribute.type.simple %} - {% if attribute.type.name == "string" %} - assert all( isinstance( element, ( str, unicode ) ) for element in attributes[ "{{ attribute.name }}" ] ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% if attribute.type.name == "integer" %} - assert all( isinstance( element, int ) for element in attributes[ "{{ attribute.name }}" ] ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% if attribute.type.name == "bool" %} - assert all( isinstance( element, bool ) for element in attributes[ "{{ attribute.name }}" ] ), attributes[ "{{ attribute.name }}" ] - {% endif %} - {% else %} - assert all( isinstance( element, dict ) for element in attributes[ "{{ attribute.name }}" ] ), attributes[ "{{ attribute.name }}" ] - {% endif %} -{% endif %} - -{% if attribute.type.cardinality == "scalar" %} - {% if attribute.type.simple %} - self._{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] - {% else %} - self._{{ attribute.name }} = None if attributes[ "{{ attribute.name }}" ] is None else {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, attributes[ "{{ attribute.name }}" ], completed = False ) - {% endif %} -{% endif %} - -{% if attribute.type.cardinality == "list" %} - {% if attribute.type.simple %} - self._{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] - {% else %} - self._{{ attribute.name }} = [ - {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) - for element in attributes[ "{{ attribute.name }}" ] - ] - {% endif %} -{% endif %} - -{% if attribute.type.cardinality == "dict" %} - {% if attribute.type.simple %} - self._{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] - {% else %} - self._{{ attribute.name }} = { - key : {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) - for key, element in attributes[ "{{ attribute.name }}" ].iteritems() - } - {% endif %} -{% endif %} - -{% endfor %} + {% if attribute.type.name != "@todo" %} + {% with simple_or_complex=attribute.type.simple|yesno:"simple,complex_as_dict" %} + if "{{ attribute.name }}" in attributes: # pragma no branch + {% with template_name="GithubObject.IsInstance."|add:attribute.type.cardinality|add:"."|add:simple_or_complex|add:".py" %} + assert attributes[ "{{ attribute.name }}" ] is None or {% include template_name with variable="attributes[ \""|add:attribute.name|add:"\" ]"|safe type=attribute.type only %}, attributes[ "{{ attribute.name }}" ] + {% endwith %} + {% endwith %} + {% endif %} + + {% with simple_or_complex=attribute.type.simple|yesno:"simple,complex" %} + {% with template_name="GithubObject.AttributeValue."|add:simple_or_complex|add:".py" %} + self._{{ attribute.name }} = {% include template_name %} + {% endwith %} + {% endwith %} + +{% endfor %} diff --git a/codegen/templates/GithubObject.IsInstance.bool.py b/codegen/templates/GithubObject.IsInstance.bool.py new file mode 100644 index 00000000..c88a1b6c --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.bool.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type="bool" only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.dict.complex_as_dict.py b/codegen/templates/GithubObject.IsInstance.dict.complex_as_dict.py new file mode 100644 index 00000000..e3a657f4 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.dict.complex_as_dict.py @@ -0,0 +1 @@ +all( {% include "GithubObject.IsInstance.py" with variable="element" type="dict" only %} for element in {{ variable }}.itervalues() ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.dict.py b/codegen/templates/GithubObject.IsInstance.dict.py new file mode 100644 index 00000000..f102cce8 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.dict.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type="dict" only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.integer.py b/codegen/templates/GithubObject.IsInstance.integer.py new file mode 100644 index 00000000..f4e9f687 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.integer.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type="int" only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.list.complex.py b/codegen/templates/GithubObject.IsInstance.list.complex.py new file mode 100644 index 00000000..86c72f49 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.list.complex.py @@ -0,0 +1 @@ +all( {% include "GithubObject.IsInstance.py" with variable="element" type=type.name|add:"."|add:type.name only %} for element in {{ variable }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.list.complex_as_dict.py b/codegen/templates/GithubObject.IsInstance.list.complex_as_dict.py new file mode 100644 index 00000000..e57b67d1 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.list.complex_as_dict.py @@ -0,0 +1 @@ +all( {% include "GithubObject.IsInstance.py" with variable="element" type="dict" only %} for element in {{ variable }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.list.simple.py b/codegen/templates/GithubObject.IsInstance.list.simple.py new file mode 100644 index 00000000..c5b2074a --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.list.simple.py @@ -0,0 +1 @@ +all( {% with template_name="GithubObject.IsInstance."|add:type.name|add:".py" %}{% include template_name with variable="element" only %}{% endwith %} for element in {{ variable }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.py b/codegen/templates/GithubObject.IsInstance.py new file mode 100644 index 00000000..77b97461 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.py @@ -0,0 +1 @@ +isinstance( {{ variable }}, {{ type }} ) \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.scalar.complex.py b/codegen/templates/GithubObject.IsInstance.scalar.complex.py new file mode 100644 index 00000000..affcf4fc --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.scalar.complex.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type=type.name|add:"."|add:type.name only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.scalar.complex_as_dict.py b/codegen/templates/GithubObject.IsInstance.scalar.complex_as_dict.py new file mode 100644 index 00000000..f102cce8 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.scalar.complex_as_dict.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type="dict" only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.scalar.simple.py b/codegen/templates/GithubObject.IsInstance.scalar.simple.py new file mode 100644 index 00000000..cfcd8989 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.scalar.simple.py @@ -0,0 +1 @@ +{% with template_name="GithubObject.IsInstance."|add:type.name|add:".py" %}{% include template_name with variable=variable only %}{% endwith %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.IsInstance.string.py b/codegen/templates/GithubObject.IsInstance.string.py new file mode 100644 index 00000000..7fbdf970 --- /dev/null +++ b/codegen/templates/GithubObject.IsInstance.string.py @@ -0,0 +1 @@ +{% include "GithubObject.IsInstance.py" with variable=variable type="( str, unicode )" only %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.MethodBody.CheckArguments.py b/codegen/templates/GithubObject.MethodBody.CheckArguments.py index 8f51f0c9..4cdb10bc 100644 --- a/codegen/templates/GithubObject.MethodBody.CheckArguments.py +++ b/codegen/templates/GithubObject.MethodBody.CheckArguments.py @@ -1,94 +1,27 @@ -{% for parameter in method.mandatoryParameters %} - {% if parameter.type.cardinality == "scalar" %} - - {% if parameter.type.simple %} - {% if parameter.type.name == "string" %} - assert isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "integer" %} - assert isinstance( {{ parameter.name }}, int ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "bool" %} - assert isinstance( {{ parameter.name }}, bool ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "dict" %} - assert isinstance( {{ parameter.name }}, dict ), {{ parameter.name }} - {% endif %} - {% else %} - assert isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }} - {% endif %} - - {% else %} - - {% if parameter.type.simple %} - {% if parameter.type.name == "string" %} - assert all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "integer" %} - assert all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "bool" %} - assert all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% else %} - assert all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - - {% endif %} -{% endfor %} -{% for parameter in method.optionalParameters %} - {% if parameter.type.cardinality == "scalar" %} - - {% if parameter.type.simple %} - {% if parameter.type.name == "string" %} - assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "integer" %} - assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, int ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "bool" %} - assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, bool ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "dict" %} - assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, dict ), {{ parameter.name }} - {% endif %} - {% else %} - assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }} - {% endif %} - - {% else %} - - {% if parameter.type.simple %} - {% if parameter.type.name == "string" %} - assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "integer" %} - assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% if parameter.type.name == "bool" %} - assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - {% else %} - assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }} - {% endif %} - - {% endif %} -{% endfor %} - -{% if method.variadicParameter %} - {% if method.variadicParameter.type.name != "@todo" %} - {% if method.variadicParameter.type.simple %} - {% if method.variadicParameter.type.name == "string" %} - assert all( isinstance( {{ method.variadicParameter.name }}, ( str, unicode ) ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s - {% endif %} - {% if parameter.type.name == "integer" %} - assert all( isinstance( {{ method.variadicParameter.name }}, int ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s - {% endif %} - {% if parameter.type.name == "bool" %} - assert all( isinstance( {{ method.variadicParameter.name }}, bool ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s - {% endif %} - {% else %} - assert all( isinstance( {{ method.variadicParameter.name }}, {{ method.variadicParameter.type.name }}.{{ method.variadicParameter.type.name }} ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s - {% endif %} - {% endif %} -{% endif %} +{% for parameter in method.mandatoryParameters %} + {% if parameter.type.name != "@todo" %} + {% with simple_or_complex=parameter.type.simple|yesno:"simple,complex" %} + {% with template_name="GithubObject.IsInstance."|add:parameter.type.cardinality|add:"."|add:simple_or_complex|add:".py" %} + assert {% include template_name with variable=parameter.name type=parameter.type only %}, {{ parameter.name }} + {% endwith %} + {% endwith %} + {% endif %} +{% endfor %} + +{% for parameter in method.optionalParameters %} + {% if parameter.type.name != "@todo" %} + {% with simple_or_complex=parameter.type.simple|yesno:"simple,complex" %} + {% with template_name="GithubObject.IsInstance."|add:parameter.type.cardinality|add:"."|add:simple_or_complex|add:".py" %} + assert {{ parameter.name }} is GithubObject.NotSet or {% include template_name with variable=parameter.name type=parameter.type only %}, {{ parameter.name }} + {% endwith %} + {% endwith %} + {% endif %} +{% endfor %} + +{% if method.variadicParameter %} + {% with simple_or_complex=method.variadicParameter.type.simple|yesno:"simple,complex" %} + {% with template_name="GithubObject.IsInstance.list."|add:simple_or_complex|add:".py" %} + assert {% include template_name with variable=method.variadicParameter.name|add:"s" type=method.variadicParameter.type only %}, {{ method.variadicParameter.name }}s + {% endwith %} + {% endwith %} +{% endif %} diff --git a/codegen/templates/GithubObject.PublicAttributes.py b/codegen/templates/GithubObject.PublicAttributes.py index c92f927e..67df2db5 100644 --- a/codegen/templates/GithubObject.PublicAttributes.py +++ b/codegen/templates/GithubObject.PublicAttributes.py @@ -1,8 +1,8 @@ -{% for attribute in class.attributes|dictsort:"name" %} - @property - def {{ attribute.name }}( self ): -{% if class.isCompletable %} - self._completeIfNotSet( self._{{ attribute.name }} ) -{% endif %} - return self._NoneIfNotSet( self._{{ attribute.name }} ) -{% endfor %} +{% for attribute in class.attributes|dictsort:"name" %} + @property + def {{ attribute.name }}( self ): +{% if class.isCompletable %} + self._completeIfNotSet( self._{{ attribute.name }} ) +{% endif %} + return self._NoneIfNotSet( self._{{ attribute.name }} ) +{% endfor %} diff --git a/codegen/templates/GithubObject.PublicMethods.py b/codegen/templates/GithubObject.PublicMethods.py index bac34efa..1b4297b4 100644 --- a/codegen/templates/GithubObject.PublicMethods.py +++ b/codegen/templates/GithubObject.PublicMethods.py @@ -1,6 +1,6 @@ -{% for method in class.methods|dictsort:"name" %} - 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.UseResult.py" %} -{% endfor %} +{% for method in class.methods|dictsort:"name" %} + 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.UseResult.py" %} +{% endfor %} diff --git a/src/github/AuthenticatedUser.py b/src/github/AuthenticatedUser.py index 4395e8d8..942612c0 100644 --- a/src/github/AuthenticatedUser.py +++ b/src/github/AuthenticatedUser.py @@ -141,7 +141,7 @@ class AuthenticatedUser( GithubObject.GithubObject ): return self._NoneIfNotSet( self._url ) def add_to_emails( self, *emails ): - assert all( isinstance( email, ( str, unicode ) ) for email in emails ), emails + assert all( isinstance( element, ( str, unicode ) ) for element in emails ), emails post_parameters = emails status, headers, data = self._request( "POST", @@ -555,7 +555,7 @@ class AuthenticatedUser( GithubObject.GithubObject ): return status == 204 def remove_from_emails( self, *emails ): - assert all( isinstance( email, ( str, unicode ) ) for email in emails ), emails + assert all( isinstance( element, ( str, unicode ) ) for element in emails ), emails post_parameters = emails status, headers, data = self._request( "DELETE", diff --git a/src/github/Authorization.py b/src/github/Authorization.py index cb1b4aa4..a8c963a5 100644 --- a/src/github/Authorization.py +++ b/src/github/Authorization.py @@ -114,7 +114,7 @@ class Authorization( GithubObject.GithubObject ): assert attributes[ "note_url" ] is None or isinstance( attributes[ "note_url" ], ( str, unicode ) ), attributes[ "note_url" ] self._note_url = attributes[ "note_url" ] if "scopes" in attributes: # pragma no branch - assert all( isinstance( element, ( str, unicode ) ) for element in attributes[ "scopes" ] ), attributes[ "scopes" ] + assert attributes[ "scopes" ] is None or all( isinstance( element, ( str, unicode ) ) for element in attributes[ "scopes" ] ), attributes[ "scopes" ] self._scopes = attributes[ "scopes" ] if "token" in attributes: # pragma no branch assert attributes[ "token" ] is None or isinstance( attributes[ "token" ], ( str, unicode ) ), attributes[ "token" ] diff --git a/src/github/Commit.py b/src/github/Commit.py index 012ebcbb..376e816f 100644 --- a/src/github/Commit.py +++ b/src/github/Commit.py @@ -111,14 +111,14 @@ class Commit( GithubObject.GithubObject ): assert attributes[ "committer" ] is None or isinstance( attributes[ "committer" ], dict ), attributes[ "committer" ] self._committer = None if attributes[ "committer" ] is None else NamedUser.NamedUser( self._requester, attributes[ "committer" ], completed = False ) if "files" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "files" ] ), attributes[ "files" ] - self._files = [ + assert attributes[ "files" ] is None or all( isinstance( element, dict ) for element in attributes[ "files" ] ), attributes[ "files" ] + self._files = None if attributes[ "files" ] is None else [ File.File( self._requester, element, completed = False ) for element in attributes[ "files" ] ] if "parents" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ] - self._parents = [ + assert attributes[ "parents" ] is None or all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ] + self._parents = None if attributes[ "parents" ] is None else [ Commit( self._requester, element, completed = False ) for element in attributes[ "parents" ] ] diff --git a/src/github/Comparison.py b/src/github/Comparison.py index 13265f9c..fc8bb182 100644 --- a/src/github/Comparison.py +++ b/src/github/Comparison.py @@ -92,8 +92,8 @@ class Comparison( GithubObject.GithubObject ): assert attributes[ "behind_by" ] is None or isinstance( attributes[ "behind_by" ], int ), attributes[ "behind_by" ] self._behind_by = attributes[ "behind_by" ] if "commits" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "commits" ] ), attributes[ "commits" ] - self._commits = [ + assert attributes[ "commits" ] is None or all( isinstance( element, dict ) for element in attributes[ "commits" ] ), attributes[ "commits" ] + self._commits = None if attributes[ "commits" ] is None else [ Commit.Commit( self._requester, element, completed = False ) for element in attributes[ "commits" ] ] @@ -101,8 +101,8 @@ class Comparison( GithubObject.GithubObject ): assert attributes[ "diff_url" ] is None or isinstance( attributes[ "diff_url" ], ( str, unicode ) ), attributes[ "diff_url" ] self._diff_url = attributes[ "diff_url" ] if "files" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "files" ] ), attributes[ "files" ] - self._files = [ + assert attributes[ "files" ] is None or all( isinstance( element, dict ) for element in attributes[ "files" ] ), attributes[ "files" ] + self._files = None if attributes[ "files" ] is None else [ File.File( self._requester, element, completed = False ) for element in attributes[ "files" ] ] diff --git a/src/github/Gist.py b/src/github/Gist.py index ab670415..25391177 100644 --- a/src/github/Gist.py +++ b/src/github/Gist.py @@ -216,7 +216,8 @@ class Gist( GithubObject.GithubObject ): assert attributes[ "description" ] is None or isinstance( attributes[ "description" ], ( str, unicode ) ), attributes[ "description" ] self._description = attributes[ "description" ] if "files" in attributes: # pragma no branch - self._files = { + assert attributes[ "files" ] is None or all( isinstance( element, dict ) for element in attributes[ "files" ].itervalues() ), attributes[ "files" ] + self._files = None if attributes[ "files" ] is None else { key : GistFile.GistFile( self._requester, element, completed = False ) for key, element in attributes[ "files" ].iteritems() } @@ -224,8 +225,8 @@ class Gist( GithubObject.GithubObject ): assert attributes[ "fork_of" ] is None or isinstance( attributes[ "fork_of" ], dict ), attributes[ "fork_of" ] self._fork_of = None if attributes[ "fork_of" ] is None else Gist( self._requester, attributes[ "fork_of" ], completed = False ) if "forks" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "forks" ] ), attributes[ "forks" ] - self._forks = [ + assert attributes[ "forks" ] is None or all( isinstance( element, dict ) for element in attributes[ "forks" ] ), attributes[ "forks" ] + self._forks = None if attributes[ "forks" ] is None else [ Gist( self._requester, element, completed = False ) for element in attributes[ "forks" ] ] @@ -236,8 +237,8 @@ class Gist( GithubObject.GithubObject ): assert attributes[ "git_push_url" ] is None or isinstance( attributes[ "git_push_url" ], ( str, unicode ) ), attributes[ "git_push_url" ] self._git_push_url = attributes[ "git_push_url" ] if "history" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "history" ] ), attributes[ "history" ] - self._history = [ + assert attributes[ "history" ] is None or all( isinstance( element, dict ) for element in attributes[ "history" ] ), attributes[ "history" ] + self._history = None if attributes[ "history" ] is None else [ GistHistoryState.GistHistoryState( self._requester, element, completed = False ) for element in attributes[ "history" ] ] diff --git a/src/github/GitCommit.py b/src/github/GitCommit.py index 5470d22a..732fff15 100644 --- a/src/github/GitCommit.py +++ b/src/github/GitCommit.py @@ -63,8 +63,8 @@ class GitCommit( GithubObject.GithubObject ): assert attributes[ "message" ] is None or isinstance( attributes[ "message" ], ( str, unicode ) ), attributes[ "message" ] self._message = attributes[ "message" ] if "parents" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ] - self._parents = [ + assert attributes[ "parents" ] is None or all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ] + self._parents = None if attributes[ "parents" ] is None else [ GitCommit( self._requester, element, completed = False ) for element in attributes[ "parents" ] ] diff --git a/src/github/GitTree.py b/src/github/GitTree.py index 1435b745..8e1a51f5 100644 --- a/src/github/GitTree.py +++ b/src/github/GitTree.py @@ -31,8 +31,8 @@ class GitTree( GithubObject.GithubObject ): assert attributes[ "sha" ] is None or isinstance( attributes[ "sha" ], ( str, unicode ) ), attributes[ "sha" ] self._sha = attributes[ "sha" ] if "tree" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "tree" ] ), attributes[ "tree" ] - self._tree = [ + assert attributes[ "tree" ] is None or all( isinstance( element, dict ) for element in attributes[ "tree" ] ), attributes[ "tree" ] + self._tree = None if attributes[ "tree" ] is None else [ GitTreeElement.GitTreeElement( self._requester, element, completed = False ) for element in attributes[ "tree" ] ] diff --git a/src/github/Hook.py b/src/github/Hook.py index 14149065..e5118dea 100644 --- a/src/github/Hook.py +++ b/src/github/Hook.py @@ -119,7 +119,7 @@ class Hook( GithubObject.GithubObject ): assert attributes[ "created_at" ] is None or isinstance( attributes[ "created_at" ], ( str, unicode ) ), attributes[ "created_at" ] self._created_at = attributes[ "created_at" ] if "events" in attributes: # pragma no branch - assert all( isinstance( element, ( str, unicode ) ) for element in attributes[ "events" ] ), attributes[ "events" ] + assert attributes[ "events" ] is None or all( isinstance( element, ( str, unicode ) ) for element in attributes[ "events" ] ), attributes[ "events" ] self._events = attributes[ "events" ] if "id" in attributes: # pragma no branch assert attributes[ "id" ] is None or isinstance( attributes[ "id" ], int ), attributes[ "id" ] diff --git a/src/github/Issue.py b/src/github/Issue.py index 40fc673f..21c5bc46 100644 --- a/src/github/Issue.py +++ b/src/github/Issue.py @@ -104,7 +104,7 @@ class Issue( GithubObject.GithubObject ): return self._NoneIfNotSet( self._user ) def add_to_labels( self, *labels ): - assert all( isinstance( label, Label.Label ) for label in labels ), labels + assert all( isinstance( element, Label.Label ) for element in labels ), labels post_parameters = [ label._identity for label in labels ] status, headers, data = self._request( "POST", @@ -233,7 +233,7 @@ class Issue( GithubObject.GithubObject ): self._checkStatus( status, data ) def set_labels( self, *labels ): - assert all( isinstance( label, Label.Label ) for label in labels ), labels + assert all( isinstance( element, Label.Label ) for element in labels ), labels post_parameters = [ label._identity for label in labels ] status, headers, data = self._request( "PUT", @@ -289,8 +289,8 @@ class Issue( GithubObject.GithubObject ): assert attributes[ "id" ] is None or isinstance( attributes[ "id" ], int ), attributes[ "id" ] self._id = attributes[ "id" ] if "labels" in attributes: # pragma no branch - assert all( isinstance( element, dict ) for element in attributes[ "labels" ] ), attributes[ "labels" ] - self._labels = [ + assert attributes[ "labels" ] is None or all( isinstance( element, dict ) for element in attributes[ "labels" ] ), attributes[ "labels" ] + self._labels = None if attributes[ "labels" ] is None else [ Label.Label( self._requester, element, completed = False ) for element in attributes[ "labels" ] ]