Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e06ab1

Browse files
committed
The usual :)
1 parent 45cd9de commit 3e06ab1

27 files changed

Lines changed: 1252 additions & 1113 deletions

Lib/dos-8x3/basehttp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787

8888
class HTTPServer(SocketServer.TCPServer):
8989

90+
allow_reuse_address = 1 # Seems to make sense in testing environment
91+
9092
def server_bind(self):
9193
"""Override server_bind to store the server name."""
9294
SocketServer.TCPServer.server_bind(self)

Lib/dos-8x3/configpa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def read(self, filenames):
197197
configuration files in the list will be read. A single
198198
filename may also be given.
199199
"""
200-
if type(filenames) is type(''):
200+
if type(filenames) in [type(''), type(u'')]:
201201
filenames = [filenames]
202202
for filename in filenames:
203203
try:

Lib/dos-8x3/nturl2pa.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Convert a NT pathname to a file URL and vice versa."""
22

33
def url2pathname(url):
4-
""" Convert a URL to a DOS path...
4+
r"""Convert a URL to a DOS path.
5+
56
///C|/foo/bar/spam.foo
67
78
becomes
@@ -32,7 +33,8 @@ def url2pathname(url):
3233
return path
3334

3435
def pathname2url(p):
35-
""" Convert a DOS path name to a file url...
36+
r"""Convert a DOS path name to a file url.
37+
3638
C:\foo\bar\spam.foo
3739
3840
becomes

Lib/dos-8x3/reconver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env python1.5
22

3-
"""Convert old ("regex") regular expressions to new syntax ("re").
3+
r"""Convert old ("regex") regular expressions to new syntax ("re").
44
55
When imported as a module, there are two functions, with their own
66
strings:

Lib/dos-8x3/rlcomple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def global_matches(self, text):
7676
__builtin__.__dict__.keys(),
7777
__main__.__dict__.keys()]:
7878
for word in list:
79-
if word[:n] == text:
79+
if word[:n] == text and word != "__builtins__":
8080
matches.append(word)
8181
return matches
8282

@@ -106,7 +106,7 @@ def attr_matches(self, text):
106106
matches = []
107107
n = len(attr)
108108
for word in words:
109-
if word[:n] == attr:
109+
if word[:n] == attr and word != "__builtins__":
110110
matches.append("%s.%s" % (expr, word))
111111
return matches
112112

Lib/dos-8x3/simpleht.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
"""
77

88

9-
__version__ = "0.3"
9+
__version__ = "0.4"
1010

1111

1212
import os
1313
import string
1414
import posixpath
1515
import BaseHTTPServer
1616
import urllib
17+
import cgi
18+
from StringIO import StringIO
1719

1820

1921
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
@@ -57,16 +59,62 @@ def send_head(self):
5759
5860
"""
5961
path = self.translate_path(self.path)
62+
f = None
6063
if os.path.isdir(path):
61-
self.send_error(403, "Directory listing not supported")
62-
return None
64+
for index in "index.html", "index.htm":
65+
index = os.path.join(path, index)
66+
if os.path.exists(index):
67+
path = index
68+
break
69+
else:
70+
return self.list_directory(path)
71+
ctype = self.guess_type(path)
72+
if ctype.startswith('text/'):
73+
mode = 'r'
74+
else:
75+
mode = 'rb'
6376
try:
64-
f = open(path, 'rb')
77+
f = open(path, mode)
6578
except IOError:
6679
self.send_error(404, "File not found")
6780
return None
6881
self.send_response(200)
69-
self.send_header("Content-type", self.guess_type(path))
82+
self.send_header("Content-type", ctype)
83+
self.end_headers()
84+
return f
85+
86+
def list_directory(self, path):
87+
"""Helper to produce a directory listing (absent index.html).
88+
89+
Return value is either a file object, or None (indicating an
90+
error). In either case, the headers are sent, making the
91+
interface the same as for send_head().
92+
93+
"""
94+
try:
95+
list = os.listdir(path)
96+
except os.error:
97+
self.send_error(404, "No permission to list directory");
98+
return None
99+
list.sort(lambda a, b: cmp(a.lower(), b.lower()))
100+
f = StringIO()
101+
f.write("<h2>Directory listing for %s</h2>\n" % self.path)
102+
f.write("<hr>\n<ul>\n")
103+
for name in list:
104+
fullname = os.path.join(path, name)
105+
displayname = linkname = name = cgi.escape(name)
106+
# Append / for directories or @ for symbolic links
107+
if os.path.isdir(fullname):
108+
displayname = name + "/"
109+
linkname = name + os.sep
110+
if os.path.islink(fullname):
111+
displayname = name + "@"
112+
# Note: a link to a directory displays with @ and links with /
113+
f.write('<li><a href="%s">%s</a>\n' % (linkname, displayname))
114+
f.write("</ul>\n<hr>\n")
115+
f.seek(0)
116+
self.send_response(200)
117+
self.send_header("Content-type", "text/html")
70118
self.end_headers()
71119
return f
72120

Lib/dos-8x3/socketse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class TCPServer:
141141
- address_family
142142
- socket_type
143143
- request_queue_size (only for stream sockets)
144+
- reuse_address
144145
145146
Instance variables:
146147
@@ -156,6 +157,8 @@ class TCPServer:
156157

157158
request_queue_size = 5
158159

160+
allow_reuse_address = 0
161+
159162
def __init__(self, server_address, RequestHandlerClass):
160163
"""Constructor. May be extended, do not override."""
161164
self.server_address = server_address
@@ -171,6 +174,8 @@ def server_bind(self):
171174
May be overridden.
172175
173176
"""
177+
if self.allow_reuse_address:
178+
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
174179
self.socket.bind(self.server_address)
175180

176181
def server_activate(self):

0 commit comments

Comments
 (0)