From 0ddf741cab5409350f7214feffd2067e49fd1f9a Mon Sep 17 00:00:00 2001 From: Lars Hupfeldt Date: Thu, 13 Feb 2014 20:45:19 +0100 Subject: [PATCH] basestring, unicode, str compatibility --- jenkinsapi/job.py | 9 +++++++-- jenkinsapi/jobs.py | 9 +++++++-- jenkinsapi_tests/systests/test_scm.py | 6 +++++- jenkinsapi_tests/unittests/test_build_scm_git.py | 6 +++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index ae3abc2..b8f97d9 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -500,8 +500,13 @@ class Job(JenkinsBase, MutableJenkinsThing): Also refresh the ElementTree object since the config has changed """ url = self.get_config_xml_url() - if isinstance(config, unicode): - config = str(config) + try: + if isinstance(config, unicode): # pylint: disable=undefined-variable + config = str(config) + except NameError: + # Python3 already a str + pass + response = self.jenkins.requester.post_url(url, params={}, data=config) self._element_tree = ET.fromstring(config) return response.text diff --git a/jenkinsapi/jobs.py b/jenkinsapi/jobs.py index c7fcd9a..7035afd 100644 --- a/jenkinsapi/jobs.py +++ b/jenkinsapi/jobs.py @@ -89,8 +89,13 @@ class Jobs(object): return self[job_name] params = {'name': job_name} - if isinstance(config, unicode): - config = str(config) + try: + if isinstance(config, unicode): # pylint: disable=undefined-variable + config = str(config) + except NameError: + # Python3 already a str + pass + self.jenkins.requester.post_xml_and_confirm_status( self.jenkins.get_create_url(), data=config, diff --git a/jenkinsapi_tests/systests/test_scm.py b/jenkinsapi_tests/systests/test_scm.py index dd79836..3147fb0 100644 --- a/jenkinsapi_tests/systests/test_scm.py +++ b/jenkinsapi_tests/systests/test_scm.py @@ -17,7 +17,11 @@ # ii.block(until='completed') # self.assertFalse(ii.is_running()) # b = ii.get_build() -# self.assertIsInstance(b.get_revision(), basestring) +# try: +# self.assertIsInstance(b.get_revision(), basestring) +# except NameError: +# # Python3 +# self.assertIsInstance(b.get_revision(), str) # if __name__ == '__main__': # unittest.main() diff --git a/jenkinsapi_tests/unittests/test_build_scm_git.py b/jenkinsapi_tests/unittests/test_build_scm_git.py index cd31855..7983e59 100644 --- a/jenkinsapi_tests/unittests/test_build_scm_git.py +++ b/jenkinsapi_tests/unittests/test_build_scm_git.py @@ -98,7 +98,11 @@ class test_build(unittest.TestCase): """ Can we extract git build revision data from a build object? """ - self.assertIsInstance(self.b.get_revision(), basestring) + try: + self.assertIsInstance(self.b.get_revision(), basestring) + except NameError: + # Python3 + self.assertIsInstance(self.b.get_revision(), str) self.assertEquals(self.b.get_revision(), '7def9ed6e92580f37d00e4980c36c4d36e68f702') -- 2.7.4