"""
-__version__ = "0.4"
+__version__ = "0.5"
import os
return None
list.sort(lambda a, b: cmp(a.lower(), b.lower()))
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("<hr>\n<ul>\n")
for name in list:
# Append / for directories or @ for symbolic links
if os.path.isdir(fullname):
displayname = name + "/"
- linkname = name + os.sep
+ linkname = name + "/"
if os.path.islink(fullname):
displayname = name + "@"
# Note: a link to a directory displays with @ and links with /
MAXREPEAT = 65535
SPECIAL_CHARS = ".\\[{()*+?^$|"
-REPEAT_CHARS = "*+?{"
+REPEAT_CHARS = "*+?{"
-DIGITS = tuple("012345689")
+DIGITS = tuple("0123456789")
OCTDIGITS = tuple("01234567")
HEXDIGITS = tuple("0123456789abcdefABCDEF")
# hexadecimal escape
while source.next in HEXDIGITS and len(escape) < 4:
escape = escape + source.get()
- escape = escape[2:]
- if len(escape) != 2:
- raise error, "bogus escape: %s" % repr("\\" + escape)
- return LITERAL, int(escape, 16) & 0xff
+ if len(escape) != 4:
+ raise ValueError
+ return LITERAL, int(escape[2:], 16) & 0xff
elif escape[1:2] == "0":
# octal escape
- while source.next in OCTDIGITS and len(escape) < 5:
+ while source.next in OCTDIGITS and len(escape) < 4:
escape = escape + source.get()
return LITERAL, int(escape[1:], 8) & 0xff
elif escape[1:2] in DIGITS:
here = source.tell()
if source.next in DIGITS:
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
escape = escape + source.get()
return LITERAL, int(escape[1:], 8) & 0xff
group = _group(escape, state.groups)
if group:
return GROUPREF, group
- raise error, "bogus escape: %s" % repr(escape)
+ raise ValueError
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
assert m[0] == '3'
print ' Contents of first 3 bytes:', repr(m[0:3])
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'
m.flush()
print ' Test passed'
test_both()
-
print "Testing os module:"
import popen2
cmd = "cat"
- teststr = "abc\n"
- resultstr = teststr
+ teststr = "ab cd\n"
if os.name == "nt":
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..."
w, r = os.popen2(cmd)
w.write(teststr)
w.close()
- assert r.read() == resultstr
+ got = r.read()
+ if got.strip() != expected:
+ raise ValueError("wrote %s read %s" % (`teststr`, `got`))
print "testing popen3..."
try:
w, r, e = os.popen3([cmd])
w, r, e = os.popen3(cmd)
w.write(teststr)
w.close()
- assert r.read() == resultstr
- assert e.read() == ""
+ got = r.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[:]:
inst.wait()
- assert not popen2._active
+ if popen2._active:
+ raise ValueError("_active not empty")
print "All OK"
main()
class WindowsDefault:
def open(self, url, new=0):
- import win32api, win32con
- win32api.ShellExecute(0, "open", url, None, ".",
- win32con.SW_SHOWNORMAL)
+ self.junk = os.popen("start " + url)
def open_new(self, url):
self.open(url)