Merge lp:~marcoceppi/python-jujuclient/py3-compat into lp:~hazmat/python-jujuclient/trunk

Proposed by Marco Ceppi on 2014-01-24
Status: Needs review
Proposed branch: lp:~marcoceppi/python-jujuclient/py3-compat
Merge into: lp:~hazmat/python-jujuclient/trunk
Diff against target: 113 lines (+22/-12)
1 file modified
jujuclient.py (+22/-12)
To merge this branch: bzr merge lp:~marcoceppi/python-jujuclient/py3-compat
Reviewer Review Type Date Requested Status
Kapil Thangavelu 2014-01-24 Pending
Review via email: mp+203073@code.launchpad.net

Description of the change

Make jujuclient python3 compatible

To post a comment you must log in.
22. By Marco Ceppi on 2014-01-24

next is not __next__

23. By Marco Ceppi on 2014-01-24

next is not __next__

Kapil Thangavelu (hazmat) wrote :
Download full text (4.1 KiB)

callable is a builtin in python3..

On Fri, Jan 24, 2014 at 10:01 AM, Marco Ceppi <email address hidden> wrote:

> Marco Ceppi has proposed merging
> lp:~marcoceppi/python-jujuclient/py3-compat into lp:python-jujuclient.
>
> Requested reviews:
> Kapil Thangavelu (hazmat)
>
> For more details, see:
>
> https://code.launchpad.net/~marcoceppi/python-jujuclient/py3-compat/+merge/203073
>
> Make jujuclient python3 compatible
> --
>
> https://code.launchpad.net/~marcoceppi/python-jujuclient/py3-compat/+merge/203073
> You are requested to review the proposed merge of
> lp:~marcoceppi/python-jujuclient/py3-compat into lp:python-jujuclient.
>
> === modified file 'jujuclient.py'
> --- jujuclient.py 2014-01-22 22:29:15 +0000
> +++ jujuclient.py 2014-01-24 14:54:35 +0000
> @@ -48,17 +48,27 @@
> """
> # License: GPLv3
> # Author: Kapil Thangavelu <email address hidden>
> +from __future__ import print_function
>
> from base64 import b64encode
> from contextlib import contextmanager
>
> -import httplib
> import json
> import pprint
> import signal
> -import StringIO
> import logging
> import websocket
> +import collections
> +
> +try:
> + import httplib
> +except ImportError:
> + import http.client as httplib
> +
> +try:
> + import StringIO
> +except ImportError:
> + import io as StringIO
>
> # There are two pypi modules with the name websocket (python-websocket
> # and websocket) We utilize python-websocket, sniff and error if we
> @@ -223,7 +233,7 @@
> def _set_alarm(cls, timeout):
> try:
> handler = signal.getsignal(signal.SIGALRM)
> - if callable(handler):
> + if isinstance(handler, collections.Callable):
> if handler.__name__ == '_set_alarm':
> raise TimeoutWatchInProgress()
> raise RuntimeError(
> @@ -482,7 +492,7 @@
>
> def _prepare_strparams(self, d):
> r = {}
> - for k, v in d.items():
> + for k, v in list(d.items()):
> r[k] = str(v)
> return r
>
> @@ -734,7 +744,7 @@
> for change_set in self.watch:
> for change in change_set:
> self.process(*change)
> - if seen_initial and callable(callback):
> + if seen_initial and isinstance(callback,
> collections.Callable):
> callback(*change)
> if self.complete() is True:
> self.watch.stop()
> @@ -768,7 +778,7 @@
>
> def complete(self):
> state = {'pending': [], 'errors': []}
> - for k, v in self.units.items():
> + for k, v in list(self.units.items()):
> if v['Status'] == "error":
> state['errors'] = [v]
> elif v['Status'] != self.goal_state:
> @@ -798,7 +808,7 @@
> self.machines[data['Id']] = data
>
> def complete(self):
> - if self.machines.keys() == ['0']:
> + if list(self.machines.keys()) == ['0']:
> return True
>
>
> @@ -840,7 +850,7 @@
>
> def _translate(self, d):
> r = {}
> - for k, v in d.items():
> + for k, v in list(d.items(...

Read more...

Unmerged revisions

23. By Marco Ceppi on 2014-01-24

next is not __next__

22. By Marco Ceppi on 2014-01-24

next is not __next__

21. By Marco Ceppi on 2014-01-24

Make py3 compatible

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujuclient.py'
2--- jujuclient.py 2014-01-22 22:29:15 +0000
3+++ jujuclient.py 2014-01-24 14:54:35 +0000
4@@ -48,17 +48,27 @@
5 """
6 # License: GPLv3
7 # Author: Kapil Thangavelu <kapil.foss@gmail.com>
8+from __future__ import print_function
9
10 from base64 import b64encode
11 from contextlib import contextmanager
12
13-import httplib
14 import json
15 import pprint
16 import signal
17-import StringIO
18 import logging
19 import websocket
20+import collections
21+
22+try:
23+ import httplib
24+except ImportError:
25+ import http.client as httplib
26+
27+try:
28+ import StringIO
29+except ImportError:
30+ import io as StringIO
31
32 # There are two pypi modules with the name websocket (python-websocket
33 # and websocket) We utilize python-websocket, sniff and error if we
34@@ -223,7 +233,7 @@
35 def _set_alarm(cls, timeout):
36 try:
37 handler = signal.getsignal(signal.SIGALRM)
38- if callable(handler):
39+ if isinstance(handler, collections.Callable):
40 if handler.__name__ == '_set_alarm':
41 raise TimeoutWatchInProgress()
42 raise RuntimeError(
43@@ -482,7 +492,7 @@
44
45 def _prepare_strparams(self, d):
46 r = {}
47- for k, v in d.items():
48+ for k, v in list(d.items()):
49 r[k] = str(v)
50 return r
51
52@@ -734,7 +744,7 @@
53 for change_set in self.watch:
54 for change in change_set:
55 self.process(*change)
56- if seen_initial and callable(callback):
57+ if seen_initial and isinstance(callback, collections.Callable):
58 callback(*change)
59 if self.complete() is True:
60 self.watch.stop()
61@@ -768,7 +778,7 @@
62
63 def complete(self):
64 state = {'pending': [], 'errors': []}
65- for k, v in self.units.items():
66+ for k, v in list(self.units.items()):
67 if v['Status'] == "error":
68 state['errors'] = [v]
69 elif v['Status'] != self.goal_state:
70@@ -798,7 +808,7 @@
71 self.machines[data['Id']] = data
72
73 def complete(self):
74- if self.machines.keys() == ['0']:
75+ if list(self.machines.keys()) == ['0']:
76 return True
77
78
79@@ -840,7 +850,7 @@
80
81 def _translate(self, d):
82 r = {}
83- for k, v in d.items():
84+ for k, v in list(d.items()):
85 if k in self.remove_keys:
86 continue
87 if k in self.skip_empty_keys and not v:
88@@ -902,21 +912,21 @@
89 env.login(juju_token)
90 watcher = env.get_watch(timeout=3)
91
92- print "Env info", env.info()
93+ print("Env info", env.info())
94
95 for change_set in watcher:
96 for change in change_set:
97- print "state change", change
98+ print("state change", change)
99
100 env.deploy("test-blog", "cs:wordpress")
101 env.deploy("test-db", "cs:mysql")
102 env.add_relation("test-db", "test-blog")
103
104- print "waiting for changes for 30s"
105+ print("waiting for changes for 30s")
106 watcher.set_timeout(30)
107 for change_set in watcher:
108 for change in change_set:
109- print "state change", change
110+ print("state change", change)
111
112 env.destroy_service('test-blog')
113 env.destroy_service('test-db')

Subscribers

People subscribed via source and target branches

to all changes: