Kaydet (Commit) e2ab1451 authored tarafından Guido van Rossum's avatar Guido van Rossum

The usual.

üst 10912854
...@@ -6,7 +6,7 @@ and HEAD requests in a fairly straightforward manner. ...@@ -6,7 +6,7 @@ and HEAD requests in a fairly straightforward manner.
""" """
__version__ = "0.4" __version__ = "0.5"
import os import os
...@@ -99,6 +99,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -99,6 +99,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
return None return None
list.sort(lambda a, b: cmp(a.lower(), b.lower())) list.sort(lambda a, b: cmp(a.lower(), b.lower()))
f = StringIO() f = StringIO()
f.write("<title>Directory listing for %s</title>\n" % self.path)
f.write("<h2>Directory listing for %s</h2>\n" % self.path) f.write("<h2>Directory listing for %s</h2>\n" % self.path)
f.write("<hr>\n<ul>\n") f.write("<hr>\n<ul>\n")
for name in list: for name in list:
...@@ -107,7 +108,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -107,7 +108,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
# Append / for directories or @ for symbolic links # Append / for directories or @ for symbolic links
if os.path.isdir(fullname): if os.path.isdir(fullname):
displayname = name + "/" displayname = name + "/"
linkname = name + os.sep linkname = name + "/"
if os.path.islink(fullname): if os.path.islink(fullname):
displayname = name + "@" displayname = name + "@"
# Note: a link to a directory displays with @ and links with / # Note: a link to a directory displays with @ and links with /
......
...@@ -15,9 +15,9 @@ from sre_constants import * ...@@ -15,9 +15,9 @@ from sre_constants import *
MAXREPEAT = 65535 MAXREPEAT = 65535
SPECIAL_CHARS = ".\\[{()*+?^$|" SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{" REPEAT_CHARS = "*+?{"
DIGITS = tuple("012345689") DIGITS = tuple("0123456789")
OCTDIGITS = tuple("01234567") OCTDIGITS = tuple("01234567")
HEXDIGITS = tuple("0123456789abcdefABCDEF") HEXDIGITS = tuple("0123456789abcdefABCDEF")
...@@ -259,13 +259,12 @@ def _escape(source, escape, state): ...@@ -259,13 +259,12 @@ def _escape(source, escape, state):
# hexadecimal escape # hexadecimal escape
while source.next in HEXDIGITS and len(escape) < 4: while source.next in HEXDIGITS and len(escape) < 4:
escape = escape + source.get() escape = escape + source.get()
escape = escape[2:] if len(escape) != 4:
if len(escape) != 2: raise ValueError
raise error, "bogus escape: %s" % repr("\\" + escape) return LITERAL, int(escape[2:], 16) & 0xff
return LITERAL, int(escape, 16) & 0xff
elif escape[1:2] == "0": elif escape[1:2] == "0":
# octal escape # octal escape
while source.next in OCTDIGITS and len(escape) < 5: while source.next in OCTDIGITS and len(escape) < 4:
escape = escape + source.get() escape = escape + source.get()
return LITERAL, int(escape[1:], 8) & 0xff return LITERAL, int(escape[1:], 8) & 0xff
elif escape[1:2] in DIGITS: elif escape[1:2] in DIGITS:
...@@ -273,7 +272,8 @@ def _escape(source, escape, state): ...@@ -273,7 +272,8 @@ def _escape(source, escape, state):
here = source.tell() here = source.tell()
if source.next in DIGITS: if source.next in DIGITS:
escape = escape + source.get() escape = escape + source.get()
if escape[2] in OCTDIGITS and source.next in OCTDIGITS: if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and
source.next in OCTDIGITS):
# got three octal digits; this is an octal escape # got three octal digits; this is an octal escape
escape = escape + source.get() escape = escape + source.get()
return LITERAL, int(escape[1:], 8) & 0xff return LITERAL, int(escape[1:], 8) & 0xff
...@@ -281,7 +281,7 @@ def _escape(source, escape, state): ...@@ -281,7 +281,7 @@ def _escape(source, escape, state):
group = _group(escape, state.groups) group = _group(escape, state.groups)
if group: if group:
return GROUPREF, group return GROUPREF, group
raise error, "bogus escape: %s" % repr(escape) raise ValueError
if len(escape) == 2: if len(escape) == 2:
return LITERAL, ord(escape[1]) return LITERAL, ord(escape[1])
except ValueError: except ValueError:
......
...@@ -40,7 +40,7 @@ def test_both(): ...@@ -40,7 +40,7 @@ def test_both():
assert m[0] == '3' assert m[0] == '3'
print ' Contents of first 3 bytes:', repr(m[0:3]) print ' Contents of first 3 bytes:', repr(m[0:3])
assert m[0:3] == '3\0\0' assert m[0:3] == '3\0\0'
print ' Contents of second page:', m[PAGESIZE-1 : PAGESIZE + 7] print ' Contents of second page:', repr(m[PAGESIZE-1 : PAGESIZE + 7])
assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0' assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0'
m.flush() m.flush()
...@@ -119,4 +119,3 @@ def test_both(): ...@@ -119,4 +119,3 @@ def test_both():
print ' Test passed' print ' Test passed'
test_both() test_both()
...@@ -28,16 +28,20 @@ def _test(): ...@@ -28,16 +28,20 @@ def _test():
print "Testing os module:" print "Testing os module:"
import popen2 import popen2
cmd = "cat" cmd = "cat"
teststr = "abc\n" teststr = "ab cd\n"
resultstr = teststr
if os.name == "nt": if os.name == "nt":
cmd = "more" cmd = "more"
resultstr = "\n" + resultstr # "more" doesn't act the same way across Windows flavors,
# sometimes adding an extra newline at the start or the
# end. So we strip whitespace off both ends for comparison.
expected = teststr.strip()
print "testing popen2..." print "testing popen2..."
w, r = os.popen2(cmd) w, r = os.popen2(cmd)
w.write(teststr) w.write(teststr)
w.close() w.close()
assert r.read() == resultstr got = r.read()
if got.strip() != expected:
raise ValueError("wrote %s read %s" % (`teststr`, `got`))
print "testing popen3..." print "testing popen3..."
try: try:
w, r, e = os.popen3([cmd]) w, r, e = os.popen3([cmd])
...@@ -45,11 +49,16 @@ def _test(): ...@@ -45,11 +49,16 @@ def _test():
w, r, e = os.popen3(cmd) w, r, e = os.popen3(cmd)
w.write(teststr) w.write(teststr)
w.close() w.close()
assert r.read() == resultstr got = r.read()
assert e.read() == "" if got.strip() != expected:
raise ValueError("wrote %s read %s" % (`teststr`, `got`))
got = e.read()
if got:
raise ValueError("unexected %s on stderr" % `got`)
for inst in popen2._active[:]: for inst in popen2._active[:]:
inst.wait() inst.wait()
assert not popen2._active if popen2._active:
raise ValueError("_active not empty")
print "All OK" print "All OK"
main() main()
......
...@@ -183,9 +183,7 @@ register("grail", Grail) ...@@ -183,9 +183,7 @@ register("grail", Grail)
class WindowsDefault: class WindowsDefault:
def open(self, url, new=0): def open(self, url, new=0):
import win32api, win32con self.junk = os.popen("start " + url)
win32api.ShellExecute(0, "open", url, None, ".",
win32con.SW_SHOWNORMAL)
def open_new(self, url): def open_new(self, url):
self.open(url) self.open(url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment