From 075d3d961d4614a2a0835d5583248adfc0687a7d Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sun, 27 May 2012 13:30:38 +0100 Subject: [PATCH] Generate code for url quoting --- codegen/GenerateCode.py | 1 + .../description.000.human_readable.json | 21 ++++++++++++++-- .../description.001.normalized.json | 24 ++++++++++++------- .../templates/GithubObject.Concatenation.py | 2 +- codegen/templates/GithubObject.py | 4 ++++ src/github/Label.py | 3 +-- src/github/Repository.py | 3 +-- 7 files changed, 42 insertions(+), 16 deletions(-) diff --git a/codegen/GenerateCode.py b/codegen/GenerateCode.py index d10d7d4b..e2da2683 100644 --- a/codegen/GenerateCode.py +++ b/codegen/GenerateCode.py @@ -23,6 +23,7 @@ for class_ in description[ "classes" ]: if not thing[ "type" ][ "simple" ]: dependencies.add( thing[ "type" ][ "name" ] ) class_[ "dependencies" ] = list( dependencies ) + class_[ "needsUrllib" ] = class_[ "name" ] in [ "Label", "Repository" ] githubObjectTemplate = django.template.loader.get_template( "GithubObject.py" ) for class_ in description[ "classes" ]: diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index 43a2ef1b..2b72a091 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -760,7 +760,12 @@ { "name": "url", "type": "@todo" } ], "identity": [ - { "type": "attribute", "value": [ "name" ] } + { + "type": "urlquote", + "value": [ + { "type": "attribute", "value": [ "name" ] } + ] + } ] }, { @@ -1558,7 +1563,19 @@ ] }, "getElement": { - "parameter": { "name": "name", "type": "@todo" } + "parameter": { "name": "name", "type": "@todo" }, + "request": { + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/labels/" }, + { + "type": "urlquote", + "value": [ + { "type": "argument", "value": [ "name" ] } + ] + } + ] + } } }, { diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index c7fe59fa..dff0b9b2 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -4398,9 +4398,14 @@ "name": "Label", "identity": [ { - "type": "attribute", + "type": "urlquote", "value": [ - "name" + { + "type": "attribute", + "value": [ + "name" + ] + } ] } ], @@ -9435,16 +9440,17 @@ }, { "type": "constant", - "value": "/labels" + "value": "/labels/" }, { - "type": "constant", - "value": "/" - }, - { - "type": "argument", + "type": "urlquote", "value": [ - "name" + { + "type": "argument", + "value": [ + "name" + ] + } ] } ], diff --git a/codegen/templates/GithubObject.Concatenation.py b/codegen/templates/GithubObject.Concatenation.py index a2453681..45a61e59 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 %}{% endfor %} \ No newline at end of file +{% 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 %}{% endfor %} \ No newline at end of file diff --git a/codegen/templates/GithubObject.py b/codegen/templates/GithubObject.py index 831a0555..16ea8590 100644 --- a/codegen/templates/GithubObject.py +++ b/codegen/templates/GithubObject.py @@ -1,3 +1,7 @@ +{% if class.needsUrllib %} +import urllib +{% endif %} + import PaginatedList from GithubObject import * diff --git a/src/github/Label.py b/src/github/Label.py index a8ae7877..7f4d467b 100644 --- a/src/github/Label.py +++ b/src/github/Label.py @@ -2,7 +2,6 @@ # Do not modify it manually, your work would be lost. import urllib - import PaginatedList from GithubObject import * @@ -47,7 +46,7 @@ class Label( object ): @property def _identity( self ): - return urllib.quote( self.name ) + return urllib.quote( str( self.name ) ) def __initAttributes( self ): self.__color = None diff --git a/src/github/Repository.py b/src/github/Repository.py index 84df4662..7ef5c6bc 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -2,7 +2,6 @@ # Do not modify it manually, your work would be lost. import urllib - import PaginatedList from GithubObject import * import Branch @@ -717,7 +716,7 @@ class Repository( object ): def get_label( self, name ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/labels" + "/" + urllib.quote( name ), + str( self.url ) + "/labels/" + urllib.quote( str( name ) ), None, None )