summaryrefslogtreecommitdiff
path: root/net/tcpwatch/files/patch-2to3
blob: f86b4a788807b6bb23a809ee486a058b18c280bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
--- tcpwatch.py.orig	2004-06-17 00:03:46 UTC
+++ tcpwatch.py
@@ -71,8 +71,8 @@ Revision information:
 $Id: tcpwatch.py,v 1.9 2004/06/17 00:03:46 shane Exp $
 """
 
-from __future__ import nested_scopes
 
+
 VERSION = '1.3'
 COPYRIGHT = (
     'TCPWatch %s Copyright 2001 Shane Hathaway, Zope Corporation'
@@ -346,7 +346,7 @@ class BasicObserver:
         if not show_cr:
             data = data.replace('\r', '')
         lines = data.split('\n')
-        lines = map(escape, lines)
+        lines = list(map(escape, lines))
         s = ('\n%s' % arrow).join(lines)
         self.write(s)
 
@@ -472,13 +472,13 @@ def setupTk(titlepart, config_info, colorized=1):
     """Starts the Tk application and returns an observer factory.
     """
 
-    import Tkinter
-    from ScrolledText import ScrolledText
-    from Queue import Queue, Empty
+    import tkinter
+    from tkinter.scrolledtext import ScrolledText
+    from queue import Queue, Empty
     try:
-        from cStringIO import StringIO
+        from io import StringIO
     except ImportError:
-        from StringIO import StringIO
+        from io import StringIO
 
     startup_text = COPYRIGHT + ("""
 
@@ -489,11 +489,11 @@ the list on the left to see the data transferred.
 """ % config_info)
 
 
-    class TkTCPWatch (Tkinter.Frame):
+    class TkTCPWatch (tkinter.Frame):
         '''The tcpwatch top-level window.
         '''
         def __init__(self, master):
-            Tkinter.Frame.__init__(self, master)
+            tkinter.Frame.__init__(self, master)
             self.createWidgets()
             # connections maps ids to TkConnectionObservers.
             self.connections = {}
@@ -502,15 +502,15 @@ the list on the left to see the data transferred.
             self.processQueue()
 
         def createWidgets(self):
-            listframe = Tkinter.Frame(self)
-            listframe.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=1)
-            scrollbar = Tkinter.Scrollbar(listframe, orient=Tkinter.VERTICAL)
-            self.connectlist = Tkinter.Listbox(
+            listframe = tkinter.Frame(self)
+            listframe.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=1)
+            scrollbar = tkinter.Scrollbar(listframe, orient=tkinter.VERTICAL)
+            self.connectlist = tkinter.Listbox(
                 listframe, yscrollcommand=scrollbar.set, exportselection=0)
             scrollbar.config(command=self.connectlist.yview)
-            scrollbar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y)
+            scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
             self.connectlist.pack(
-                side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=1)
+                side=tkinter.LEFT, fill=tkinter.BOTH, expand=1)
             self.connectlist.bind('<Button-1>', self.mouseListSelect)
             self.textbox = ScrolledText(self, background="#ffffff")
             self.textbox.tag_config("message", foreground="#000000")
@@ -520,32 +520,32 @@ the list on the left to see the data transferred.
             self.textbox.tag_config("server", foreground="#770000")
             self.textbox.tag_config(
                 "serveresc", foreground="#770000", background="#dddddd")
-            self.textbox.insert(Tkinter.END, startup_text, "message")
-            self.textbox.pack(side='right', fill=Tkinter.BOTH, expand=1)
-            self.pack(fill=Tkinter.BOTH, expand=1)
+            self.textbox.insert(tkinter.END, startup_text, "message")
+            self.textbox.pack(side='right', fill=tkinter.BOTH, expand=1)
+            self.pack(fill=tkinter.BOTH, expand=1)
 
         def addConnection(self, id, conn):
             self.connections[id] = conn
             connectlist = self.connectlist
-            connectlist.insert(Tkinter.END, id)
+            connectlist.insert(tkinter.END, id)
 
         def updateConnection(self, id, output):
             if id == self.showingid:
                 textbox = self.textbox
                 for data, style in output:
-                    textbox.insert(Tkinter.END, data, style)
+                    textbox.insert(tkinter.END, data, style)
 
         def mouseListSelect(self, event=None):
             connectlist = self.connectlist
             idx = connectlist.nearest(event.y)
             sel = connectlist.get(idx)
             connections = self.connections
-            if connections.has_key(sel):
+            if sel in connections:
                 self.showingid = ''
                 output = connections[sel].getOutput()
-                self.textbox.delete(1.0, Tkinter.END)
+                self.textbox.delete(1.0, tkinter.END)
                 for data, style in output:
-                    self.textbox.insert(Tkinter.END, data, style)
+                    self.textbox.insert(tkinter.END, data, style)
                 self.showingid = sel
 
         def processQueue(self):
@@ -630,7 +630,7 @@ the list on the left to see the data transferred.
             # Escape the input data.
             was_escaped = 0
             start_idx = 0
-            for idx in xrange(len(data)):
+            for idx in range(len(data)):
                 c = data[idx]
                 escaped = (c < ' ' and c != '\n') or c >= '\x80'
                 if was_escaped != escaped:
@@ -661,7 +661,7 @@ the list on the left to see the data transferred.
 
 
     def createApp(titlepart):
-        master = Tkinter.Tk()
+        master = tkinter.Tk()
         app = TkTCPWatch(master)
         try:
             wm_title = app.master.wm_title
@@ -1165,7 +1165,7 @@ class HTTPProxyToClientConnection (ForwardingEndpoint)
         """
         first_line = request.first_line.strip()
         if not ' ' in first_line:
-            raise ValueError, ('Malformed request: %s' % first_line)
+            raise ValueError('Malformed request: %s' % first_line)
         command, url = first_line.split(' ', 1)
         pos = url.rfind(' HTTP/')
         if pos >= 0:
@@ -1187,7 +1187,7 @@ class HTTPProxyToClientConnection (ForwardingEndpoint)
             host = request.headers.get('HOST')
             path = url
         if not host:
-            raise ValueError, ('Request type not supported: %s' % url)
+            raise ValueError('Request type not supported: %s' % url)
 
         if ':' in host:
             host, port = host.split(':')
@@ -1324,7 +1324,7 @@ def main(args):
                                         'no-record-responses',
                                         'no-record-errors',
                                        ])
-    except getopt.GetoptError, msg:
+    except getopt.GetoptError as msg:
         usageError(msg)
 
     fwd_params = []
@@ -1404,15 +1404,11 @@ def main(args):
     config_info_lines = []
     title_lst = []
     if fwd_params:
-        config_info_lines.extend(map(
-            lambda args: 'Forwarding %s:%d -> %s:%d' % args, fwd_params))
-        title_lst.extend(map(
-            lambda args: '%s:%d -> %s:%d' % args, fwd_params))
+        config_info_lines.extend(['Forwarding %s:%d -> %s:%d' % args for args in fwd_params])
+        title_lst.extend(['%s:%d -> %s:%d' % args for args in fwd_params])
     if proxy_params:
-        config_info_lines.extend(map(
-            lambda args: 'HTTP proxy listening on %s:%d' % args, proxy_params))
-        title_lst.extend(map(
-            lambda args: '%s:%d -> proxy' % args, proxy_params))
+        config_info_lines.extend(['HTTP proxy listening on %s:%d' % args for args in proxy_params])
+        title_lst.extend(['%s:%d -> proxy' % args for args in proxy_params])
     if split_http:
         config_info_lines.append('HTTP connection splitting enabled.')
     if record_directory:
@@ -1469,8 +1465,8 @@ def main(args):
         # Run the main loop.
         try:
             if mainloop is not None:
-                import thread
-                thread.start_new_thread(asyncore.loop, (), {'timeout': 1.0})
+                import _thread
+                _thread.start_new_thread(asyncore.loop, (), {'timeout': 1.0})
                 mainloop()
             else:
                 asyncore.loop(timeout=1.0)