Merge lp:~myint/restview/trunk into lp:~mgedmin/restview/trunk

Proposed by Steven Myint
Status: Merged
Merged at revision: 86
Proposed branch: lp:~myint/restview/trunk
Merge into: lp:~mgedmin/restview/trunk
Diff against target: 157 lines (+36/-14)
4 files modified
restview (+1/-1)
setup.py (+3/-1)
src/restview/restviewhttp.py (+31/-11)
test.py (+1/-1)
To merge this branch: bzr merge lp:~myint/restview/trunk
Reviewer Review Type Date Requested Status
Marius Gedminas Approve
Review via email: mp+141151@code.launchpad.net

Description of the change

Support Python 3 while maintaining Python 2 support.

To post a comment you must log in.
lp:~myint/restview/trunk updated
87. By <email address hidden>

Add Python 3 classifier

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Thank you, this looks very useful!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'restview'
2--- restview 2008-07-26 10:08:59 +0000
3+++ restview 2012-12-22 14:33:22 +0000
4@@ -1,4 +1,4 @@
5-#!/usr/bin/python
6+#!/usr/bin/env python
7 import sys, os
8 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
9
10
11=== modified file 'setup.py'
12--- setup.py 2010-09-14 09:39:05 +0000
13+++ setup.py 2012-12-22 14:33:22 +0000
14@@ -9,7 +9,7 @@
15 for line in read(filename).splitlines():
16 if line.startswith('__version__'):
17 d = {}
18- exec line in d
19+ exec(line, d)
20 return d['__version__']
21 raise AssertionError("couldn't find __version__ in %s" % filename)
22
23@@ -32,6 +32,8 @@
24 'Intended Audience :: End Users/Desktop',
25 'License :: OSI Approved :: GNU General Public License (GPL)',
26 'Programming Language :: Python',
27+ 'Programming Language :: Python :: 2',
28+ 'Programming Language :: Python :: 3',
29 'Operating System :: OS Independent',
30 'Topic :: Documentation',
31 'Topic :: Internet :: WWW/HTTP :: HTTP Servers',
32
33=== modified file 'src/restview/restviewhttp.py'
34--- src/restview/restviewhttp.py 2012-10-24 12:50:41 +0000
35+++ src/restview/restviewhttp.py 2012-12-22 14:33:22 +0000
36@@ -16,6 +16,7 @@
37 Needs docutils and a web browser. Will syntax highlight if you have pygments
38 installed.
39 """
40+from __future__ import print_function
41
42 import os
43 import re
44@@ -24,10 +25,23 @@
45 import optparse
46 import threading
47 import webbrowser
48-import BaseHTTPServer
49-import SocketServer
50+
51+try:
52+ import BaseHTTPServer
53+except ImportError:
54+ import http.server as BaseHTTPServer
55+
56+try:
57+ import SocketServer
58+except ImportError:
59+ import socketserver as SocketServer
60+
61 import cgi
62-import urllib
63+
64+try:
65+ from urllib import unquote
66+except ImportError:
67+ from urllib.parse import unquote
68
69 import docutils.core
70 import docutils.writers.html4css1
71@@ -41,6 +55,12 @@
72 pygments = None
73
74
75+try:
76+ unicode
77+except NameError:
78+ unicode = str
79+
80+
81 __version__ = "1.3.0dev"
82
83
84@@ -58,7 +78,7 @@
85 content = self.do_GET_or_HEAD()
86
87 def do_GET_or_HEAD(self):
88- self.path = urllib.unquote(self.path)
89+ self.path = unquote(self.path)
90 root = self.server.renderer.root
91 command = self.server.renderer.command
92 if self.path == '/':
93@@ -119,7 +139,7 @@
94 return self.handle_rest_data(f.read())
95 finally:
96 f.close()
97- except IOError, e:
98+ except IOError as e:
99 self.log_error("%s", e)
100 self.send_error(404, "File not found")
101
102@@ -130,7 +150,7 @@
103 return self.handle_rest_data(f.read())
104 finally:
105 f.close()
106- except OSError, e:
107+ except OSError as e:
108 self.log_error("%s" % e)
109 self.send_error(404, "Command execution failed")
110
111@@ -324,7 +344,7 @@
112 try:
113 docutils.core.publish_string(rest_input, writer=writer,
114 settings_overrides=settings_overrides)
115- except Exception, e:
116+ except Exception as e:
117 return self.render_exception(e.__class__.__name__, str(e),
118 rest_input)
119 return writer.output
120@@ -415,11 +435,11 @@
121 ('', 1234)
122
123 >>> try: parse_address('notanumber')
124- ... except ValueError, e: print e
125+ ... except ValueError as e: print(e)
126 Invalid address: notanumber
127
128 >>> try: parse_address('la:la:la')
129- ... except ValueError, e: print e
130+ ... except ValueError as e: print(e)
131 Invalid address: la:la:la
132
133 """
134@@ -501,12 +521,12 @@
135 if opts.listen:
136 try:
137 server.local_address = parse_address(opts.listen)
138- except ValueError, e:
139+ except ValueError as e:
140 sys.exit(str(e))
141 host = get_host_name(server.local_address[0])
142 port = server.listen()
143 url = 'http://%s:%d/' % (host, port)
144- print "Listening on %s" % url
145+ print("Listening on %s" % url)
146 if opts.browser:
147 # launch the web browser in the background as it may block
148 t = threading.Thread(target=webbrowser.open, args=(url,))
149
150=== modified file 'test.py'
151--- test.py 2010-08-06 02:13:18 +0000
152+++ test.py 2012-12-22 14:33:22 +0000
153@@ -1,4 +1,4 @@
154-#!/usr/bin/python
155+#!/usr/bin/env python
156 import unittest
157 import doctest
158

Subscribers

People subscribed via source and target branches