[Python-checkins] CVS: python/dist/src/Lib/dos-8x3 basehttp.py,1.5,1.5.2.1 configpa.py,1.6,1.6.2.1 simpleht.py,1.5,1.5.2.1 socketse.py,1.9,1.9.2.1 sre_comp.py,1.1,1.1.2.1 sre_cons.py,1.1,1.1.2.1 sre_pars.py,1.1,1.1.2.1 test_str.py,1.8,1.8.4.1 test_uni.py,1.1,1.1.2.1 test_win.py,1.1,1.1.2.1 threadst.py,1.1,NONE
Guido van Rossum
python-dev@python.org
Sun, 3 Sep 2000 09:06:31 -0700
Update of /cvsroot/python/python/dist/src/Lib/dos-8x3
In directory slayer.i.sourceforge.net:/tmp/cvs-serv32685
Modified Files:
Tag: cnri-16-start
basehttp.py configpa.py simpleht.py socketse.py sre_comp.py
sre_cons.py sre_pars.py test_str.py test_uni.py test_win.py
Removed Files:
Tag: cnri-16-start
threadst.py
Log Message:
The usual
Index: basehttp.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/basehttp.py,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -C2 -r1.5 -r1.5.2.1
*** basehttp.py 2000/05/08 17:30:59 1.5
--- basehttp.py 2000/09/03 16:06:27 1.5.2.1
***************
*** 88,91 ****
--- 88,93 ----
class HTTPServer(SocketServer.TCPServer):
+ allow_reuse_address = 1 # Seems to make sense in testing environment
+
def server_bind(self):
"""Override server_bind to store the server name."""
Index: configpa.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/configpa.py,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -r1.6 -r1.6.2.1
*** configpa.py 2000/05/08 17:30:59 1.6
--- configpa.py 2000/09/03 16:06:27 1.6.2.1
***************
*** 198,202 ****
filename may also be given.
"""
! if type(filenames) is type(''):
filenames = [filenames]
for filename in filenames:
--- 198,202 ----
filename may also be given.
"""
! if type(filenames) in [type(''), type(u'')]:
filenames = [filenames]
for filename in filenames:
Index: simpleht.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/simpleht.py,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -C2 -r1.5 -r1.5.2.1
*** simpleht.py 2000/05/08 17:31:01 1.5
--- simpleht.py 2000/09/03 16:06:27 1.5.2.1
***************
*** 7,11 ****
! __version__ = "0.3"
--- 7,11 ----
! __version__ = "0.4"
***************
*** 15,18 ****
--- 15,20 ----
import BaseHTTPServer
import urllib
+ import cgi
+ from StringIO import StringIO
***************
*** 59,72 ****
path = self.translate_path(self.path)
if os.path.isdir(path):
! self.send_error(403, "Directory listing not supported")
! return None
! try:
! f = open(path, 'rb')
! except IOError:
! self.send_error(404, "File not found")
! return None
self.send_response(200)
! self.send_header("Content-type", self.guess_type(path))
self.end_headers()
return f
--- 61,101 ----
path = self.translate_path(self.path)
if os.path.isdir(path):
! f = self.list_directory(path)
! if f is None:
! return None
! ctype = "text/HTML"
! else:
! try:
! f = open(path, 'rb')
! except IOError:
! self.send_error(404, "File not found")
! return None
! ctype = self.guess_type(path)
self.send_response(200)
! self.send_header("Content-type", ctype)
self.end_headers()
+ return f
+
+ def list_directory(self, path):
+ try:
+ list = os.listdir(path)
+ except os.error:
+ self.send_error(404, "No permission to list directory");
+ return None
+ list.sort(lambda a, b: cmp(a.lower(), b.lower()))
+ f = StringIO()
+ f.write("<h2>Directory listing for %s</h2>\n" % self.path)
+ f.write("<hr>\n<ul>\n")
+ for name in list:
+ fullname = os.path.join(path, name)
+ displayname = name = cgi.escape(name)
+ if os.path.islink(fullname):
+ displayname = name + "@"
+ elif os.path.isdir(fullname):
+ displayname = name + "/"
+ name = name + os.sep
+ f.write('<li><a href="%s">%s</a>\n' % (name, displayname))
+ f.write("</ul>\n<hr>\n")
+ f.seek(0)
return f
Index: socketse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/socketse.py,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -C2 -r1.9 -r1.9.2.1
*** socketse.py 2000/05/08 17:31:01 1.9
--- socketse.py 2000/09/03 16:06:27 1.9.2.1
***************
*** 142,145 ****
--- 142,146 ----
- socket_type
- request_queue_size (only for stream sockets)
+ - reuse_address
Instance variables:
***************
*** 157,160 ****
--- 158,163 ----
request_queue_size = 5
+ allow_reuse_address = 0
+
def __init__(self, server_address, RequestHandlerClass):
"""Constructor. May be extended, do not override."""
***************
*** 172,175 ****
--- 175,180 ----
"""
+ if self.allow_reuse_address:
+ self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
Index: sre_comp.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/sre_comp.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -r1.1 -r1.1.2.1
*** sre_comp.py 2000/05/08 17:31:01 1.1
--- sre_comp.py 2000/09/03 16:06:27 1.1.2.1
***************
*** 1,5 ****
#
# Secret Labs' Regular Expression Engine
- # $Id$
#
# convert template to internal format
--- 1,4 ----
***************
*** 7,187 ****
# Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
#
! # This code can only be used for 1.6 alpha testing. All other use
! # require explicit permission from Secret Labs AB.
#
- # Portions of this engine have been developed in cooperation with
- # CNRI. Hewlett-Packard provided funding for 1.6 integration and
- # other compatibility work.
- #
-
- # FIXME: <fl> formalize (objectify?) and document the compiler code
- # format, so that other frontends can use this compiler
- import array, string, sys
-
import _sre
from sre_constants import *
! # find an array type code that matches the engine's code size
! for WORDSIZE in "BHil":
! if len(array.array(WORDSIZE, [0]).tostring()) == _sre.getcodesize():
! break
! else:
! raise RuntimeError, "cannot find a useable array type"
!
! # FIXME: <fl> should move some optimizations from the parser to here!
!
! class Code:
! def __init__(self):
! self.data = []
! def __len__(self):
! return len(self.data)
! def __getitem__(self, index):
! return self.data[index]
! def __setitem__(self, index, code):
! self.data[index] = code
! def append(self, code):
! self.data.append(code)
! def todata(self):
! # print self.data
! return array.array(WORDSIZE, self.data).tostring()
!
! def _lower(literal):
! # return _sre._lower(literal) # FIXME
! return string.lower(literal)
def _compile(code, pattern, flags):
! append = code.append
for op, av in pattern:
! if op is ANY:
! if "s" in flags:
! append(CODES[op]) # any character at all!
! else:
! append(CODES[NOT_LITERAL])
! append(10)
! elif op in (SUCCESS, FAILURE):
! append(CODES[op])
! elif op is AT:
! append(CODES[op])
! append(POSITIONS[av])
! elif op is BRANCH:
! append(CODES[op])
! tail = []
! for av in av[1]:
! skip = len(code); append(0)
! _compile(code, av, flags)
! append(CODES[JUMP])
! tail.append(len(code)); append(0)
! code[skip] = len(code) - skip
! append(0) # end of branch
! for tail in tail:
! code[tail] = len(code) - tail
! elif op is CALL:
! append(CODES[op])
! skip = len(code); append(0)
! _compile(code, av, flags)
! append(CODES[SUCCESS])
! code[skip] = len(code) - skip
! elif op is CATEGORY: # not used by current parser
! append(CODES[op])
! append(CATEGORIES[av])
! elif op is GROUP:
! if "i" in flags:
! append(CODES[MAP_IGNORE[op]])
! else:
! append(CODES[op])
! append(av)
! elif op is IN:
! if "i" in flags:
! append(CODES[MAP_IGNORE[op]])
! def fixup(literal):
! return ord(_lower(literal))
! else:
! append(CODES[op])
! fixup = ord
! skip = len(code); append(0)
! for op, av in av:
! append(CODES[op])
! if op is NEGATE:
! pass
! elif op is LITERAL:
! append(fixup(av))
! elif op is RANGE:
! append(fixup(av[0]))
! append(fixup(av[1]))
! elif op is CATEGORY:
! append(CATEGORIES[av])
! else:
! raise ValueError, "unsupported set operator"
! append(CODES[FAILURE])
! code[skip] = len(code) - skip
! elif op in (LITERAL, NOT_LITERAL):
! if "i" in flags:
! append(CODES[MAP_IGNORE[op]])
! append(ord(_lower(av)))
! else:
! append(CODES[op])
! append(ord(av))
! elif op is MARK:
! append(CODES[op])
! append(av)
! elif op in (REPEAT, MIN_REPEAT, MAX_REPEAT):
! lo, hi = av[2].getwidth()
! if lo == 0:
! raise SyntaxError, "cannot repeat zero-width items"
! if lo == hi == 1 and op is MAX_REPEAT:
! append(CODES[MAX_REPEAT_ONE])
! skip = len(code); append(0)
! append(av[0])
! append(av[1])
! _compile(code, av[2], flags)
! append(CODES[SUCCESS])
! code[skip] = len(code) - skip
! else:
! append(CODES[op])
! skip = len(code); append(0)
! append(av[0])
! append(av[1])
! _compile(code, av[2], flags)
! if op is MIN_REPEAT:
! append(CODES[MIN_UNTIL])
! else:
! # FIXME: MAX_REPEAT PROBABLY DOESN'T WORK (?)
! append(CODES[MAX_UNTIL])
! code[skip] = len(code) - skip
! elif op is SUBPATTERN:
! ## group = av[0]
! ## if group:
! ## append(CODES[MARK])
! ## append((group-1)*2)
! _compile(code, av[1], flags)
! ## if group:
! ## append(CODES[MARK])
! ## append((group-1)*2+1)
! else:
! raise ValueError, ("unsupported operand type", op)
!
! def compile(p, flags=()):
! # convert pattern list to internal format
! if type(p) in (type(""), type(u"")):
! import sre_parse
! pattern = p
! p = sre_parse.parse(p)
else:
! pattern = None
! # print p.getwidth()
! # print p
! code = Code()
! _compile(code, p.data, p.pattern.flags)
! code.append(CODES[SUCCESS])
! # print list(code.data)
! data = code.todata()
! if 0: # debugging
! print
! print "-" * 68
! import sre_disasm
! sre_disasm.disasm(data)
! print "-" * 68
! # print len(data), p.pattern.groups, len(p.pattern.groupdict)
! return _sre.compile(pattern, data, p.pattern.groups-1, p.pattern.groupdict)
--- 6,381 ----
# Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
#
! # See the sre.py file for information on usage and redistribution.
#
import _sre
from sre_constants import *
! MAXCODE = 65535
def _compile(code, pattern, flags):
! # internal: compile a (sub)pattern
! emit = code.append
for op, av in pattern:
! if op in (LITERAL, NOT_LITERAL):
! if flags & SRE_FLAG_IGNORECASE:
! emit(OPCODES[OP_IGNORE[op]])
! else:
! emit(OPCODES[op])
! emit(av)
! elif op is IN:
! if flags & SRE_FLAG_IGNORECASE:
! emit(OPCODES[OP_IGNORE[op]])
! def fixup(literal, flags=flags):
! return _sre.getlower(literal, flags)
! else:
! emit(OPCODES[op])
! fixup = lambda x: x
! skip = len(code); emit(0)
! _compile_charset(av, flags, code, fixup)
! code[skip] = len(code) - skip
! elif op is ANY:
! if flags & SRE_FLAG_DOTALL:
! emit(OPCODES[ANY_ALL])
! else:
! emit(OPCODES[ANY])
! elif op in (REPEAT, MIN_REPEAT, MAX_REPEAT):
! if flags & SRE_FLAG_TEMPLATE:
! raise error, "internal: unsupported template operator"
! emit(OPCODES[REPEAT])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! emit(OPCODES[SUCCESS])
! code[skip] = len(code) - skip
! elif _simple(av) and op == MAX_REPEAT:
! emit(OPCODES[REPEAT_ONE])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! emit(OPCODES[SUCCESS])
! code[skip] = len(code) - skip
! else:
! emit(OPCODES[REPEAT])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! code[skip] = len(code) - skip
! if op == MAX_REPEAT:
! emit(OPCODES[MAX_UNTIL])
! else:
! emit(OPCODES[MIN_UNTIL])
! elif op is SUBPATTERN:
! if av[0]:
! emit(OPCODES[MARK])
! emit((av[0]-1)*2)
! # _compile_info(code, av[1], flags)
! _compile(code, av[1], flags)
! if av[0]:
! emit(OPCODES[MARK])
! emit((av[0]-1)*2+1)
! elif op in (SUCCESS, FAILURE):
! emit(OPCODES[op])
! elif op in (ASSERT, ASSERT_NOT):
! emit(OPCODES[op])
! skip = len(code); emit(0)
! if av[0] >= 0:
! emit(0) # look ahead
! else:
! lo, hi = av[1].getwidth()
! if lo != hi:
! raise error, "look-behind requires fixed-width pattern"
! emit(lo) # look behind
! _compile(code, av[1], flags)
! emit(OPCODES[SUCCESS])
! code[skip] = len(code) - skip
! elif op is CALL:
! emit(OPCODES[op])
! skip = len(code); emit(0)
! _compile(code, av, flags)
! emit(OPCODES[SUCCESS])
! code[skip] = len(code) - skip
! elif op is AT:
! emit(OPCODES[op])
! if flags & SRE_FLAG_MULTILINE:
! emit(ATCODES[AT_MULTILINE.get(av, av)])
! else:
! emit(ATCODES[av])
! elif op is BRANCH:
! emit(OPCODES[op])
! tail = []
! for av in av[1]:
! skip = len(code); emit(0)
! # _compile_info(code, av, flags)
! _compile(code, av, flags)
! emit(OPCODES[JUMP])
! tail.append(len(code)); emit(0)
! code[skip] = len(code) - skip
! emit(0) # end of branch
! for tail in tail:
! code[tail] = len(code) - tail
! elif op is CATEGORY:
! emit(OPCODES[op])
! if flags & SRE_FLAG_LOCALE:
! emit(CHCODES[CH_LOCALE[av]])
! elif flags & SRE_FLAG_UNICODE:
! emit(CHCODES[CH_UNICODE[av]])
! else:
! emit(CHCODES[av])
! elif op is GROUPREF:
! if flags & SRE_FLAG_IGNORECASE:
! emit(OPCODES[OP_IGNORE[op]])
! else:
! emit(OPCODES[op])
! emit(av-1)
! else:
! raise ValueError, ("unsupported operand type", op)
!
! def _compile_charset(charset, flags, code, fixup=None):
! # compile charset subprogram
! emit = code.append
! if not fixup:
! fixup = lambda x: x
! for op, av in _optimize_charset(charset, fixup):
! emit(OPCODES[op])
! if op is NEGATE:
! pass
! elif op is LITERAL:
! emit(fixup(av))
! elif op is RANGE:
! emit(fixup(av[0]))
! emit(fixup(av[1]))
! elif op is CHARSET:
! code.extend(av)
! elif op is CATEGORY:
! if flags & SRE_FLAG_LOCALE:
! emit(CHCODES[CH_LOCALE[av]])
! elif flags & SRE_FLAG_UNICODE:
! emit(CHCODES[CH_UNICODE[av]])
! else:
! emit(CHCODES[av])
! else:
! raise error, "internal: unsupported set operator"
! emit(OPCODES[FAILURE])
!
! def _optimize_charset(charset, fixup):
! # internal: optimize character set
! out = []
! charmap = [0]*256
! try:
! for op, av in charset:
! if op is NEGATE:
! out.append((op, av))
! elif op is LITERAL:
! charmap[fixup(av)] = 1
! elif op is RANGE:
! for i in range(fixup(av[0]), fixup(av[1])+1):
! charmap[i] = 1
! elif op is CATEGORY:
! # FIXME: could append to charmap tail
! return charset # cannot compress
! except IndexError:
! # character set contains unicode characters
! return charset
! # compress character map
! i = p = n = 0
! runs = []
! for c in charmap:
! if c:
! if n == 0:
! p = i
! n = n + 1
! elif n:
! runs.append((p, n))
! n = 0
! i = i + 1
! if n:
! runs.append((p, n))
! if len(runs) <= 2:
! # use literal/range
! for p, n in runs:
! if n == 1:
! out.append((LITERAL, p))
! else:
! out.append((RANGE, (p, p+n-1)))
! if len(out) < len(charset):
! return out
else:
! # use bitmap
! data = []
! m = 1; v = 0
! for c in charmap:
! if c:
! v = v + m
! m = m << 1
! if m > MAXCODE:
! data.append(v)
! m = 1; v = 0
! out.append((CHARSET, data))
! return out
! return charset
!
! def _simple(av):
! # check if av is a "simple" operator
! lo, hi = av[2].getwidth()
! if lo == 0:
! raise error, "nothing to repeat"
! return lo == hi == 1 and av[2][0][0] != SUBPATTERN
!
! def _compile_info(code, pattern, flags):
! # internal: compile an info block. in the current version,
! # this contains min/max pattern width, and an optional literal
! # prefix or a character map
! lo, hi = pattern.getwidth()
! if lo == 0:
! return # not worth it
! # look for a literal prefix
! prefix = []
! prefix_skip = 0
! charset = [] # not used
! if not (flags & SRE_FLAG_IGNORECASE):
! # look for literal prefix
! for op, av in pattern.data:
! if op is LITERAL:
! if len(prefix) == prefix_skip:
! prefix_skip = prefix_skip + 1
! prefix.append(av)
! elif op is SUBPATTERN and len(av[1]) == 1:
! op, av = av[1][0]
! if op is LITERAL:
! prefix.append(av)
! else:
! break
! else:
! break
! # if no prefix, look for charset prefix
! if not prefix and pattern.data:
! op, av = pattern.data[0]
! if op is SUBPATTERN and av[1]:
! op, av = av[1][0]
! if op is LITERAL:
! charset.append((op, av))
! elif op is BRANCH:
! c = []
! for p in av[1]:
! if not p:
! break
! op, av = p[0]
! if op is LITERAL:
! c.append((op, av))
! else:
! break
! else:
! charset = c
! elif op is BRANCH:
! c = []
! for p in av[1]:
! if not p:
! break
! op, av = p[0]
! if op is LITERAL:
! c.append((op, av))
! else:
! break
! else:
! charset = c
! elif op is IN:
! charset = av
! ## if prefix:
! ## print "*** PREFIX", prefix, prefix_skip
! ## if charset:
! ## print "*** CHARSET", charset
! # add an info block
! emit = code.append
! emit(OPCODES[INFO])
! skip = len(code); emit(0)
! # literal flag
! mask = 0
! if prefix:
! mask = SRE_INFO_PREFIX
! if len(prefix) == prefix_skip == len(pattern.data):
! mask = mask + SRE_INFO_LITERAL
! elif charset:
! mask = mask + SRE_INFO_CHARSET
! emit(mask)
! # pattern length
! if lo < MAXCODE:
! emit(lo)
! else:
! emit(MAXCODE)
! prefix = prefix[:MAXCODE]
! if hi < MAXCODE:
! emit(hi)
! else:
! emit(0)
! # add literal prefix
! if prefix:
! emit(len(prefix)) # length
! emit(prefix_skip) # skip
! code.extend(prefix)
! # generate overlap table
! table = [-1] + ([0]*len(prefix))
! for i in range(len(prefix)):
! table[i+1] = table[i]+1
! while table[i+1] > 0 and prefix[i] != prefix[table[i+1]-1]:
! table[i+1] = table[table[i+1]-1]+1
! code.extend(table[1:]) # don't store first entry
! elif charset:
! _compile_charset(charset, 0, code)
! code[skip] = len(code) - skip
!
! STRING_TYPES = [type("")]
!
! try:
! STRING_TYPES.append(type(unicode("")))
! except NameError:
! pass
!
! def _code(p, flags):
!
! flags = p.pattern.flags | flags
! code = []
!
! # compile info block
! _compile_info(code, p, flags)
!
! # compile the pattern
! _compile(code, p.data, flags)
!
! code.append(OPCODES[SUCCESS])
!
! return code
!
! def compile(p, flags=0):
! # internal: convert pattern list to internal format
!
! if type(p) in STRING_TYPES:
! import sre_parse
! pattern = p
! p = sre_parse.parse(p, flags)
! else:
! pattern = None
!
! code = _code(p, flags)
!
! # print code
!
! # FIXME: <fl> get rid of this limitation!
! assert p.pattern.groups <= 100,\
! "sorry, but this version only supports 100 named groups"
!
! # map in either direction
! groupindex = p.pattern.groupdict
! indexgroup = [None] * p.pattern.groups
! for k, i in groupindex.items():
! indexgroup[i] = k
!
! return _sre.compile(
! pattern, flags, code,
! p.pattern.groups-1,
! groupindex, indexgroup
! )
Index: sre_cons.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/sre_cons.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -r1.1 -r1.1.2.1
*** sre_cons.py 2000/05/08 17:31:01 1.1
--- sre_cons.py 2000/09/03 16:06:27 1.1.2.1
***************
*** 1,5 ****
#
# Secret Labs' Regular Expression Engine
- # $Id$
#
# various symbols used by the regular expression engine.
--- 1,4 ----
***************
*** 8,18 ****
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # This code can only be used for 1.6 alpha testing. All other use
! # require explicit permission from Secret Labs AB.
#
! # Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 1.6 integration and
! # other compatibility work.
! #
# operators
--- 7,17 ----
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # See the sre.py file for information on usage and redistribution.
#
!
! # should this really be here?
!
! class error(Exception):
! pass
# operators
***************
*** 22,34 ****
ANY = "any"
ASSERT = "assert"
AT = "at"
BRANCH = "branch"
CALL = "call"
CATEGORY = "category"
! GROUP = "group"
! GROUP_IGNORE = "group_ignore"
IN = "in"
IN_IGNORE = "in_ignore"
JUMP = "jump"
LITERAL = "literal"
--- 21,37 ----
ANY = "any"
+ ANY_ALL = "any_all"
ASSERT = "assert"
+ ASSERT_NOT = "assert_not"
AT = "at"
BRANCH = "branch"
CALL = "call"
CATEGORY = "category"
! CHARSET = "charset"
! GROUPREF = "groupref"
! GROUPREF_IGNORE = "groupref_ignore"
IN = "in"
IN_IGNORE = "in_ignore"
+ INFO = "info"
JUMP = "jump"
LITERAL = "literal"
***************
*** 36,40 ****
MARK = "mark"
MAX_REPEAT = "max_repeat"
- MAX_REPEAT_ONE = "max_repeat_one"
MAX_UNTIL = "max_until"
MIN_REPEAT = "min_repeat"
--- 39,42 ----
***************
*** 45,58 ****
RANGE = "range"
REPEAT = "repeat"
SUBPATTERN = "subpattern"
# positions
AT_BEGINNING = "at_beginning"
AT_BOUNDARY = "at_boundary"
AT_NON_BOUNDARY = "at_non_boundary"
AT_END = "at_end"
# categories
-
CATEGORY_DIGIT = "category_digit"
CATEGORY_NOT_DIGIT = "category_not_digit"
--- 47,62 ----
RANGE = "range"
REPEAT = "repeat"
+ REPEAT_ONE = "repeat_one"
SUBPATTERN = "subpattern"
# positions
AT_BEGINNING = "at_beginning"
+ AT_BEGINNING_LINE = "at_beginning_line"
AT_BOUNDARY = "at_boundary"
AT_NON_BOUNDARY = "at_non_boundary"
AT_END = "at_end"
+ AT_END_LINE = "at_end_line"
# categories
CATEGORY_DIGIT = "category_digit"
CATEGORY_NOT_DIGIT = "category_not_digit"
***************
*** 61,131 ****
CATEGORY_WORD = "category_word"
CATEGORY_NOT_WORD = "category_not_word"
! CODES = [
# failure=0 success=1 (just because it looks better that way :-)
FAILURE, SUCCESS,
! ANY,
! ASSERT,
AT,
BRANCH,
CALL,
CATEGORY,
! GROUP, GROUP_IGNORE,
IN, IN_IGNORE,
JUMP,
LITERAL, LITERAL_IGNORE,
MARK,
! MAX_REPEAT, MAX_UNTIL,
! MAX_REPEAT_ONE,
! MIN_REPEAT, MIN_UNTIL,
NOT_LITERAL, NOT_LITERAL_IGNORE,
NEGATE,
RANGE,
! REPEAT
]
! # convert to dictionary
! c = {}
! i = 0
! for code in CODES:
! c[code] = i
! i = i + 1
! CODES = c
# replacement operations for "ignore case" mode
! MAP_IGNORE = {
! GROUP: GROUP_IGNORE,
IN: IN_IGNORE,
LITERAL: LITERAL_IGNORE,
NOT_LITERAL: NOT_LITERAL_IGNORE
}
! POSITIONS = {
! AT_BEGINNING: ord("a"),
! AT_BOUNDARY: ord("b"),
! AT_NON_BOUNDARY: ord("B"),
! AT_END: ord("z"),
}
! CATEGORIES = {
! CATEGORY_DIGIT: ord("d"),
! CATEGORY_NOT_DIGIT: ord("D"),
! CATEGORY_SPACE: ord("s"),
! CATEGORY_NOT_SPACE: ord("S"),
! CATEGORY_WORD: ord("w"),
! CATEGORY_NOT_WORD: ord("W"),
}
if __name__ == "__main__":
import string
! items = CODES.items()
! items.sort(lambda a, b: cmp(a[1], b[1]))
f = open("sre_constants.h", "w")
! f.write("/* generated by sre_constants.py */\n")
! for k, v in items:
! f.write("#define SRE_OP_" + string.upper(k) + " " + str(v) + "\n")
f.close()
print "done"
--- 65,226 ----
CATEGORY_WORD = "category_word"
CATEGORY_NOT_WORD = "category_not_word"
+ CATEGORY_LINEBREAK = "category_linebreak"
+ CATEGORY_NOT_LINEBREAK = "category_not_linebreak"
+ CATEGORY_LOC_WORD = "category_loc_word"
+ CATEGORY_LOC_NOT_WORD = "category_loc_not_word"
+ CATEGORY_UNI_DIGIT = "category_uni_digit"
+ CATEGORY_UNI_NOT_DIGIT = "category_uni_not_digit"
+ CATEGORY_UNI_SPACE = "category_uni_space"
+ CATEGORY_UNI_NOT_SPACE = "category_uni_not_space"
+ CATEGORY_UNI_WORD = "category_uni_word"
+ CATEGORY_UNI_NOT_WORD = "category_uni_not_word"
+ CATEGORY_UNI_LINEBREAK = "category_uni_linebreak"
+ CATEGORY_UNI_NOT_LINEBREAK = "category_uni_not_linebreak"
! OPCODES = [
# failure=0 success=1 (just because it looks better that way :-)
FAILURE, SUCCESS,
! ANY, ANY_ALL,
! ASSERT, ASSERT_NOT,
AT,
BRANCH,
CALL,
CATEGORY,
! CHARSET,
! GROUPREF, GROUPREF_IGNORE,
IN, IN_IGNORE,
+ INFO,
JUMP,
LITERAL, LITERAL_IGNORE,
MARK,
! MAX_UNTIL,
! MIN_UNTIL,
NOT_LITERAL, NOT_LITERAL_IGNORE,
NEGATE,
RANGE,
! REPEAT,
! REPEAT_ONE,
! SUBPATTERN
!
! ]
+ ATCODES = [
+ AT_BEGINNING, AT_BEGINNING_LINE, AT_BOUNDARY,
+ AT_NON_BOUNDARY, AT_END, AT_END_LINE
]
! CHCODES = [
! CATEGORY_DIGIT, CATEGORY_NOT_DIGIT, CATEGORY_SPACE,
! CATEGORY_NOT_SPACE, CATEGORY_WORD, CATEGORY_NOT_WORD,
! CATEGORY_LINEBREAK, CATEGORY_NOT_LINEBREAK, CATEGORY_LOC_WORD,
! CATEGORY_LOC_NOT_WORD, CATEGORY_UNI_DIGIT, CATEGORY_UNI_NOT_DIGIT,
! CATEGORY_UNI_SPACE, CATEGORY_UNI_NOT_SPACE, CATEGORY_UNI_WORD,
! CATEGORY_UNI_NOT_WORD, CATEGORY_UNI_LINEBREAK,
! CATEGORY_UNI_NOT_LINEBREAK
! ]
!
! def makedict(list):
! d = {}
! i = 0
! for item in list:
! d[item] = i
! i = i + 1
! return d
!
! OPCODES = makedict(OPCODES)
! ATCODES = makedict(ATCODES)
! CHCODES = makedict(CHCODES)
# replacement operations for "ignore case" mode
! OP_IGNORE = {
! GROUPREF: GROUPREF_IGNORE,
IN: IN_IGNORE,
LITERAL: LITERAL_IGNORE,
NOT_LITERAL: NOT_LITERAL_IGNORE
}
+
+ AT_MULTILINE = {
+ AT_BEGINNING: AT_BEGINNING_LINE,
+ AT_END: AT_END_LINE
+ }
! CH_LOCALE = {
! CATEGORY_DIGIT: CATEGORY_DIGIT,
! CATEGORY_NOT_DIGIT: CATEGORY_NOT_DIGIT,
! CATEGORY_SPACE: CATEGORY_SPACE,
! CATEGORY_NOT_SPACE: CATEGORY_NOT_SPACE,
! CATEGORY_WORD: CATEGORY_LOC_WORD,
! CATEGORY_NOT_WORD: CATEGORY_LOC_NOT_WORD,
! CATEGORY_LINEBREAK: CATEGORY_LINEBREAK,
! CATEGORY_NOT_LINEBREAK: CATEGORY_NOT_LINEBREAK
}
! CH_UNICODE = {
! CATEGORY_DIGIT: CATEGORY_UNI_DIGIT,
! CATEGORY_NOT_DIGIT: CATEGORY_UNI_NOT_DIGIT,
! CATEGORY_SPACE: CATEGORY_UNI_SPACE,
! CATEGORY_NOT_SPACE: CATEGORY_UNI_NOT_SPACE,
! CATEGORY_WORD: CATEGORY_UNI_WORD,
! CATEGORY_NOT_WORD: CATEGORY_UNI_NOT_WORD,
! CATEGORY_LINEBREAK: CATEGORY_UNI_LINEBREAK,
! CATEGORY_NOT_LINEBREAK: CATEGORY_UNI_NOT_LINEBREAK
}
+ # flags
+ SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking)
+ SRE_FLAG_IGNORECASE = 2 # case insensitive
+ SRE_FLAG_LOCALE = 4 # honour system locale
+ SRE_FLAG_MULTILINE = 8 # treat target as multiline string
+ SRE_FLAG_DOTALL = 16 # treat target as a single string
+ SRE_FLAG_UNICODE = 32 # use unicode locale
+ SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments
+
+ # flags for INFO primitive
+ SRE_INFO_PREFIX = 1 # has prefix
+ SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix)
+ SRE_INFO_CHARSET = 4 # pattern starts with character from given set
+
if __name__ == "__main__":
import string
! def dump(f, d, prefix):
! items = d.items()
! items.sort(lambda a, b: cmp(a[1], b[1]))
! for k, v in items:
! f.write("#define %s_%s %s\n" % (prefix, string.upper(k), v))
f = open("sre_constants.h", "w")
! f.write("""\
! /*
! * Secret Labs' Regular Expression Engine
! *
! * regular expression matching engine
! *
! * NOTE: This file is generated by sre_constants.py. If you need
! * to change anything in here, edit sre_constants.py and run it.
! *
! * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
! *
! * See the _sre.c file for information on usage and redistribution.
! */
!
! """)
!
! dump(f, OPCODES, "SRE_OP")
! dump(f, ATCODES, "SRE")
! dump(f, CHCODES, "SRE")
!
! f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE)
! f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE)
! f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE)
! f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE)
! f.write("#define SRE_FLAG_DOTALL %d\n" % SRE_FLAG_DOTALL)
! f.write("#define SRE_FLAG_UNICODE %d\n" % SRE_FLAG_UNICODE)
! f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
!
! f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
! f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
! f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
!
f.close()
print "done"
Index: sre_pars.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/sre_pars.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -r1.1 -r1.1.2.1
*** sre_pars.py 2000/05/08 17:31:01 1.1
--- sre_pars.py 2000/09/03 16:06:27 1.1.2.1
***************
*** 1,22 ****
#
# Secret Labs' Regular Expression Engine
- # $Id$
#
! # convert re-style regular expression to SRE template. the current
! # implementation is somewhat incomplete, and not very fast. should
! # definitely be rewritten before Python 1.6 goes beta.
#
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
[...1127 lines suppressed...]
! def expand_template(template, match):
! # FIXME: <fl> this is sooooo slow. drop in the slicelist
! # code instead
! p = []
! a = p.append
! sep = match.string[:0]
! if type(sep) is type(""):
! char = chr
! else:
! char = unichr
! for c, s in template:
! if c is LITERAL:
! a(char(s))
! elif c is MARK:
! s = match.group(s)
! if s is None:
! raise error, "empty group"
! a(s)
! return string.join(p, sep)
Index: test_str.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/test_str.py,v
retrieving revision 1.8
retrieving revision 1.8.4.1
diff -C2 -r1.8 -r1.8.4.1
*** test_str.py 1998/03/26 22:14:05 1.8
--- test_str.py 2000/09/03 16:06:27 1.8.4.1
***************
*** 1,87 ****
from test_support import verbose
! import strop, sys
! def test(name, input, output, *args):
if verbose:
! print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
! f = getattr(strop, name)
try:
! value = apply(f, (input,) + args)
! except:
! value = sys.exc_type
! if value != output:
! if verbose:
! print 'no'
! print f, `input`, `output`, `value`
! else:
! if verbose:
! print 'yes'
!
! test('atoi', " 1 ", 1)
! test('atoi', " 1x", ValueError)
! test('atoi', " x1 ", ValueError)
! test('atol', " 1 ", 1L)
! test('atol', " 1x ", ValueError)
! test('atol', " x1 ", ValueError)
! test('atof', " 1 ", 1.0)
! test('atof', " 1x ", ValueError)
! test('atof', " x1 ", ValueError)
!
! test('capitalize', ' hello ', ' hello ')
! test('capitalize', 'hello ', 'Hello ')
! test('find', 'abcdefghiabc', 0, 'abc')
! test('find', 'abcdefghiabc', 9, 'abc', 1)
! test('find', 'abcdefghiabc', -1, 'def', 4)
! test('rfind', 'abcdefghiabc', 9, 'abc')
! test('lower', 'HeLLo', 'hello')
! test('upper', 'HeLLo', 'HELLO')
!
! transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
!
! test('maketrans', 'abc', transtable, 'xyz')
! test('maketrans', 'abc', ValueError, 'xyzq')
!
! test('split', 'this is the split function',
! ['this', 'is', 'the', 'split', 'function'])
! test('split', 'a|b|c|d', ['a', 'b', 'c', 'd'], '|')
! test('split', 'a|b|c|d', ['a', 'b', 'c|d'], '|', 2)
! test('split', 'a b c d', ['a', 'b c d'], None, 1)
! test('split', 'a b c d', ['a', 'b', 'c d'], None, 2)
! test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 3)
! test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 4)
! test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 0)
! test('split', 'a b c d', ['a', 'b', 'c d'], None, 2)
!
! # join now works with any sequence type
! class Sequence:
! def __init__(self): self.seq = 'wxyz'
! def __len__(self): return len(self.seq)
! def __getitem__(self, i): return self.seq[i]
!
! test('join', ['a', 'b', 'c', 'd'], 'a b c d')
! test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
! test('join', Sequence(), 'w x y z')
!
! # try a few long ones
! print strop.join(['x' * 100] * 100, ':')
! print strop.join(('x' * 100,) * 100, ':')
!
! test('strip', ' hello ', 'hello')
! test('lstrip', ' hello ', 'hello ')
! test('rstrip', ' hello ', ' hello')
!
! test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
! test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')
!
! test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
! test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
! test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
! test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
! test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 0)
! test('replace', 'one!two!three!', 'one@two@three@', '!', '@')
! test('replace', 'one!two!three!', 'one!two!three!', 'x', '@')
! test('replace', 'one!two!three!', 'one!two!three!', 'x', '@', 2)
!
! strop.whitespace
! strop.lowercase
! strop.uppercase
--- 1,134 ----
+ #! /usr/bin/env python
+
+ # Sanity checker for time.strftime
+
+ import time, calendar, sys, string, os, re
from test_support import verbose
!
! def main():
! global verbose
! now = time.time()
! strftest(now)
! verbose = 0
! # Try a bunch of dates and times, chosen to vary through time of
! # day and daylight saving time
! for j in range(-5, 5):
! for i in range(25):
! strftest(now + (i + j*100)*23*3603)
! def strftest(now):
if verbose:
! print "strftime test for", time.ctime(now)
! nowsecs = str(long(now))[:-1]
! gmt = time.gmtime(now)
! now = time.localtime(now)
!
! if now[3] < 12: ampm='AM'
! else: ampm='PM'
!
! jan1 = time.localtime(time.mktime((now[0], 1, 1) + (0,)*6))
!
try:
! if now[8]: tz = time.tzname[1]
! else: tz = time.tzname[0]
! except AttributeError:
! tz = ''
!
! if now[3] > 12: clock12 = now[3] - 12
! elif now[3] > 0: clock12 = now[3]
! else: clock12 = 12
!
! expectations = (
! ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
! ('%A', calendar.day_name[now[6]], 'full weekday name'),
! ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
! ('%B', calendar.month_name[now[1]], 'full month name'),
! # %c see below
! ('%d', '%02d' % now[2], 'day of month as number (00-31)'),
! ('%H', '%02d' % now[3], 'hour (00-23)'),
! ('%I', '%02d' % clock12, 'hour (01-12)'),
! ('%j', '%03d' % now[7], 'julian day (001-366)'),
! ('%m', '%02d' % now[1], 'month as number (01-12)'),
! ('%M', '%02d' % now[4], 'minute, (00-59)'),
! ('%p', ampm, 'AM or PM as appropriate'),
! ('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
! ('%U', '%02d' % ((now[7] + jan1[6])/7),
! 'week number of the year (Sun 1st)'),
! ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
! ('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)/7),
! 'week number of the year (Mon 1st)'),
! # %x see below
! ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
! ('%y', '%02d' % (now[0]%100), 'year without century'),
! ('%Y', '%d' % now[0], 'year with century'),
! # %Z see below
! ('%%', '%', 'single percent sign'),
! )
!
! nonstandard_expectations = (
! # These are standard but don't have predictable output
! ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
! ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
! '%m/%d/%y %H:%M:%S'),
! ('%Z', '%s' % tz, 'time zone name'),
!
! # These are some platform specific extensions
! ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
! ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'),
! ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
! ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
! ('%n', '\n', 'newline character'),
! ('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm),
! '%I:%M:%S %p'),
! ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
! ('%s', nowsecs, 'seconds since the Epoch in UCT'),
! ('%t', '\t', 'tab character'),
! ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
! ('%3y', '%03d' % (now[0]%100),
! 'year without century rendered using fieldwidth'),
! )
!
! if verbose:
! print "Strftime test, platform: %s, Python version: %s" % \
! (sys.platform, string.split(sys.version)[0])
!
! for e in expectations:
! try:
! result = time.strftime(e[0], now)
! except ValueError, error:
! print "Standard '%s' format gave error:" % e[0], error
! continue
! if re.match(e[1], result): continue
! if not result or result[0] == '%':
! print "Does not support standard '%s' format (%s)" % (e[0], e[2])
! else:
! print "Conflict for %s (%s):" % (e[0], e[2])
! print " Expected %s, but got %s" % (e[1], result)
!
! for e in nonstandard_expectations:
! try:
! result = time.strftime(e[0], now)
! except ValueError, result:
! if verbose:
! print "Error for nonstandard '%s' format (%s): %s" % \
! (e[0], e[2], str(result))
! continue
! if re.match(e[1], result):
! if verbose:
! print "Supports nonstandard '%s' format (%s)" % (e[0], e[2])
! elif not result or result[0] == '%':
! if verbose:
! print "Does not appear to support '%s' format (%s)" % (e[0],
! e[2])
! else:
! if verbose:
! print "Conflict for nonstandard '%s' format (%s):" % (e[0],
! e[2])
! print " Expected %s, but got %s" % (e[1], result)
!
! def fixasctime(s):
! if s[8] == ' ':
! s = s[:8] + '0' + s[9:]
! return s
!
! main()
Index: test_uni.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/test_uni.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -r1.1 -r1.1.2.1
*** test_uni.py 2000/05/08 17:31:03 1.1
--- test_uni.py 2000/09/03 16:06:27 1.1.2.1
***************
*** 1,3 ****
! """ Test script for the Unicode implementation.
Written by Marc-Andre Lemburg (mal@lemburg.com).
--- 1,3 ----
! """ Test script for the unicodedata module.
Written by Marc-Andre Lemburg (mal@lemburg.com).
***************
*** 5,401 ****
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
! """
from test_support import verbose
import sys
! def test(method, input, output, *args):
! if verbose:
! print '%s.%s%s =? %s... ' % (repr(input), method, args, output),
! try:
! f = getattr(input, method)
! value = apply(f, args)
! except:
! value = sys.exc_type
! exc = sys.exc_info()[:2]
! else:
! exc = None
! if value != output:
! if verbose:
! print 'no'
! print '*',f, `input`, `output`, `value`
! if exc:
! print ' value == %s: %s' % (exc)
! else:
! if verbose:
! print 'yes'
!
! test('capitalize', u' hello ', u' hello ')
! test('capitalize', u'hello ', u'Hello ')
!
! test('title', u' hello ', u' Hello ')
! test('title', u'hello ', u'Hello ')
! test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
! test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String')
! test('title', u"getInt", u'Getint')
!
! test('find', u'abcdefghiabc', 0, u'abc')
! test('find', u'abcdefghiabc', 9, u'abc', 1)
! test('find', u'abcdefghiabc', -1, u'def', 4)
!
! test('rfind', u'abcdefghiabc', 9, u'abc')
!
! test('lower', u'HeLLo', u'hello')
! test('lower', u'hello', u'hello')
!
! test('upper', u'HeLLo', u'HELLO')
! test('upper', u'HELLO', u'HELLO')
!
! if 0:
! transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
!
! test('maketrans', u'abc', transtable, u'xyz')
! test('maketrans', u'abc', ValueError, u'xyzq')
!
! test('split', u'this is the split function',
! [u'this', u'is', u'the', u'split', u'function'])
! test('split', u'a|b|c|d', [u'a', u'b', u'c', u'd'], u'|')
! test('split', u'a|b|c|d', [u'a', u'b', u'c|d'], u'|', 2)
! test('split', u'a b c d', [u'a', u'b c d'], None, 1)
! test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
! test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 3)
! test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 4)
! test('split', u'a b c d', [u'a b c d'], None, 0)
! test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
! test('split', u'a b c d ', [u'a', u'b', u'c', u'd'])
!
! # join now works with any sequence type
! class Sequence:
! def __init__(self): self.seq = 'wxyz'
! def __len__(self): return len(self.seq)
! def __getitem__(self, i): return self.seq[i]
!
! test('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd'])
! test('join', u'', u'abcd', (u'a', u'b', u'c', u'd'))
! test('join', u' ', u'w x y z', Sequence())
! test('join', u' ', TypeError, 7)
!
! class BadSeq(Sequence):
! def __init__(self): self.seq = [7, u'hello', 123L]
!
! test('join', u' ', TypeError, BadSeq())
!
! result = u''
! for i in range(10):
! if i > 0:
! result = result + u':'
! result = result + u'x'*10
! test('join', u':', result, [u'x' * 10] * 10)
! test('join', u':', result, (u'x' * 10,) * 10)
!
! test('strip', u' hello ', u'hello')
! test('lstrip', u' hello ', u'hello ')
! test('rstrip', u' hello ', u' hello')
! test('strip', u'hello', u'hello')
!
! test('swapcase', u'HeLLo cOmpUteRs', u'hEllO CoMPuTErS')
!
! if 0:
! test('translate', u'xyzabcdef', u'xyzxyz', transtable, u'def')
!
! table = string.maketrans('a', u'A')
! test('translate', u'abc', u'Abc', table)
! test('translate', u'xyz', u'xyz', table)
!
! test('replace', u'one!two!three!', u'one@two!three!', u'!', u'@', 1)
! test('replace', u'one!two!three!', u'onetwothree', '!', '')
! test('replace', u'one!two!three!', u'one@two@three!', u'!', u'@', 2)
! test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 3)
! test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 4)
! test('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0)
! test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
! test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
! test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
!
! test('startswith', u'hello', 1, u'he')
! test('startswith', u'hello', 1, u'hello')
! test('startswith', u'hello', 0, u'hello world')
! test('startswith', u'hello', 1, u'')
! test('startswith', u'hello', 0, u'ello')
! test('startswith', u'hello', 1, u'ello', 1)
! test('startswith', u'hello', 1, u'o', 4)
! test('startswith', u'hello', 0, u'o', 5)
! test('startswith', u'hello', 1, u'', 5)
! test('startswith', u'hello', 0, u'lo', 6)
! test('startswith', u'helloworld', 1, u'lowo', 3)
! test('startswith', u'helloworld', 1, u'lowo', 3, 7)
! test('startswith', u'helloworld', 0, u'lowo', 3, 6)
!
! test('endswith', u'hello', 1, u'lo')
! test('endswith', u'hello', 0, u'he')
! test('endswith', u'hello', 1, u'')
! test('endswith', u'hello', 0, u'hello world')
! test('endswith', u'helloworld', 0, u'worl')
! test('endswith', u'helloworld', 1, u'worl', 3, 9)
! test('endswith', u'helloworld', 1, u'world', 3, 12)
! test('endswith', u'helloworld', 1, u'lowo', 1, 7)
! test('endswith', u'helloworld', 1, u'lowo', 2, 7)
! test('endswith', u'helloworld', 1, u'lowo', 3, 7)
! test('endswith', u'helloworld', 0, u'lowo', 4, 7)
! test('endswith', u'helloworld', 0, u'lowo', 3, 8)
! test('endswith', u'ab', 0, u'ab', 0, 1)
! test('endswith', u'ab', 0, u'ab', 0, 0)
!
! test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi')
! test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
! test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4)
! test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4)
!
! if 0:
! test('capwords', u'abc def ghi', u'Abc Def Ghi')
! test('capwords', u'abc\tdef\nghi', u'Abc Def Ghi')
! test('capwords', u'abc\t def \nghi', u'Abc Def Ghi')
!
! # Comparisons:
! print 'Testing Unicode comparisons...',
! assert u'abc' == 'abc'
! assert 'abc' == u'abc'
! assert u'abc' == u'abc'
! assert u'abcd' > 'abc'
! assert 'abcd' > u'abc'
! assert u'abcd' > u'abc'
! assert u'abc' < 'abcd'
! assert 'abc' < u'abcd'
! assert u'abc' < u'abcd'
! print 'done.'
!
! test('ljust', u'abc', u'abc ', 10)
! test('rjust', u'abc', u' abc', 10)
! test('center', u'abc', u' abc ', 10)
! test('ljust', u'abc', u'abc ', 6)
! test('rjust', u'abc', u' abc', 6)
! test('center', u'abc', u' abc ', 6)
! test('ljust', u'abc', u'abc', 2)
! test('rjust', u'abc', u'abc', 2)
! test('center', u'abc', u'abc', 2)
!
! test('islower', u'a', 1)
! test('islower', u'A', 0)
! test('islower', u'\n', 0)
! test('islower', u'\u1FFc', 0)
! test('islower', u'abc', 1)
! test('islower', u'aBc', 0)
! test('islower', u'abc\n', 1)
!
! test('isupper', u'a', 0)
! test('isupper', u'A', 1)
! test('isupper', u'\n', 0)
! test('isupper', u'\u1FFc', 0)
! test('isupper', u'ABC', 1)
! test('isupper', u'AbC', 0)
! test('isupper', u'ABC\n', 1)
!
! test('istitle', u'a', 0)
! test('istitle', u'A', 1)
! test('istitle', u'\n', 0)
! test('istitle', u'\u1FFc', 1)
! test('istitle', u'A Titlecased Line', 1)
! test('istitle', u'A\nTitlecased Line', 1)
! test('istitle', u'A Titlecased, Line', 1)
! test('istitle', u'Greek \u1FFcitlecases ...', 1)
! test('istitle', u'Not a capitalized String', 0)
! test('istitle', u'Not\ta Titlecase String', 0)
! test('istitle', u'Not--a Titlecase String', 0)
!
! test('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi'])
! test('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi'])
! test('splitlines', u"abc\ndef\r\nghi", [u'abc', u'def', u'ghi'])
! test('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi'])
! test('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u''])
! test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u''])
! test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], 1)
!
! test('translate', u"abababc", u'bbbc', {ord('a'):None})
! test('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')})
! test('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'})
!
! # Contains:
! print 'Testing Unicode contains method...',
! assert ('a' in u'abdb') == 1
! assert ('a' in u'bdab') == 1
! assert ('a' in u'bdaba') == 1
! assert ('a' in u'bdba') == 1
! assert ('a' in u'bdba') == 1
! assert (u'a' in u'bdba') == 1
! assert (u'a' in u'bdb') == 0
! assert (u'a' in 'bdb') == 0
! assert (u'a' in 'bdba') == 1
! assert (u'a' in ('a',1,None)) == 1
! assert (u'a' in (1,None,'a')) == 1
! assert (u'a' in (1,None,u'a')) == 1
! assert ('a' in ('a',1,None)) == 1
! assert ('a' in (1,None,'a')) == 1
! assert ('a' in (1,None,u'a')) == 1
! assert ('a' in ('x',1,u'y')) == 0
! assert ('a' in ('x',1,None)) == 0
! print 'done.'
!
! # Formatting:
! print 'Testing Unicode formatting strings...',
! assert u"%s, %s" % (u"abc", "abc") == u'abc, abc'
! assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3) == u'abc, abc, 1, 2.000000, 3.00'
! assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3) == u'abc, abc, 1, -2.000000, 3.00'
! assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5) == u'abc, abc, -1, -2.000000, 3.50'
! assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57) == u'abc, abc, -1, -2.000000, 3.57'
! assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57) == u'abc, abc, -1, -2.000000, 1003.57'
! assert u"%c" % (u"abc",) == u'a'
! assert u"%c" % ("abc",) == u'a'
! assert u"%c" % (34,) == u'"'
! assert u"%c" % (36,) == u'$'
! assert u"%r, %r" % (u"abc", "abc") == u"u'abc', 'abc'"
! assert u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def'
! assert u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"} == u'abc, def'
! # formatting jobs delegated from the string implementation:
! assert '...%(foo)s...' % {'foo':u"abc"} == u'...abc...'
! assert '...%(foo)s...' % {'foo':"abc"} == '...abc...'
! assert '...%(foo)s...' % {u'foo':"abc"} == '...abc...'
! assert '...%(foo)s...' % {u'foo':u"abc"} == u'...abc...'
! assert '...%(foo)s...' % {u'foo':u"abc",'def':123} == u'...abc...'
! assert '...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...'
! assert '...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...'
! assert '...%s...' % u"abc" == u'...abc...'
! print 'done.'
!
! # Test builtin codecs
! print 'Testing builtin codecs...',
!
! assert unicode('hello','ascii') == u'hello'
! assert unicode('hello','utf-8') == u'hello'
! assert unicode('hello','utf8') == u'hello'
! assert unicode('hello','latin-1') == u'hello'
!
! try:
! u'Andr\202 x'.encode('ascii')
! u'Andr\202 x'.encode('ascii','strict')
! except ValueError:
! pass
! else:
! raise AssertionError, "u'Andr\202'.encode('ascii') failed to raise an exception"
! assert u'Andr\202 x'.encode('ascii','ignore') == "Andr x"
! assert u'Andr\202 x'.encode('ascii','replace') == "Andr? x"
!
! try:
! unicode('Andr\202 x','ascii')
! unicode('Andr\202 x','ascii','strict')
! except ValueError:
! pass
! else:
! raise AssertionError, "unicode('Andr\202') failed to raise an exception"
! assert unicode('Andr\202 x','ascii','ignore') == u"Andr x"
! assert unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x'
!
! assert u'hello'.encode('ascii') == 'hello'
! assert u'hello'.encode('utf-8') == 'hello'
! assert u'hello'.encode('utf8') == 'hello'
! assert u'hello'.encode('utf-16-le') == 'h\000e\000l\000l\000o\000'
! assert u'hello'.encode('utf-16-be') == '\000h\000e\000l\000l\000o'
! assert u'hello'.encode('latin-1') == 'hello'
!
! u = u''.join(map(unichr, range(1024)))
! for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
! 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
! assert unicode(u.encode(encoding),encoding) == u
!
! u = u''.join(map(unichr, range(256)))
! for encoding in (
! 'latin-1',
! ):
! try:
! assert unicode(u.encode(encoding),encoding) == u
! except AssertionError:
! print '*** codec "%s" failed round-trip' % encoding
! except ValueError,why:
! print '*** codec for "%s" failed: %s' % (encoding, why)
!
! u = u''.join(map(unichr, range(128)))
! for encoding in (
! 'ascii',
! ):
! try:
! assert unicode(u.encode(encoding),encoding) == u
! except AssertionError:
! print '*** codec "%s" failed round-trip' % encoding
! except ValueError,why:
! print '*** codec for "%s" failed: %s' % (encoding, why)
!
! print 'done.'
!
! print 'Testing standard mapping codecs...',
!
! print '0-127...',
! s = ''.join(map(chr, range(128)))
! for encoding in (
! 'cp037', 'cp1026',
! 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
! 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
! 'cp863', 'cp865', 'cp866',
! 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
! 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
! 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
! 'mac_cyrillic', 'mac_latin2',
!
! 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
! 'cp1256', 'cp1257', 'cp1258',
! 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
!
! 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
! 'cp1006', 'cp875', 'iso8859_8',
!
! ### These have undefined mappings:
! #'cp424',
!
! ):
! try:
! assert unicode(s,encoding).encode(encoding) == s
! except AssertionError:
! print '*** codec "%s" failed round-trip' % encoding
! except ValueError,why:
! print '*** codec for "%s" failed: %s' % (encoding, why)
!
! print '128-255...',
! s = ''.join(map(chr, range(128,256)))
! for encoding in (
! 'cp037', 'cp1026',
! 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
! 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
! 'cp863', 'cp865', 'cp866',
! 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
! 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
! 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
! 'mac_cyrillic', 'mac_latin2',
!
! ### These have undefined mappings:
! #'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
! #'cp1256', 'cp1257', 'cp1258',
! #'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
! #'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
!
! ### These fail the round-trip:
! #'cp1006', 'cp875', 'iso8859_8',
!
! ):
! try:
! assert unicode(s,encoding).encode(encoding) == s
! except AssertionError:
! print '*** codec "%s" failed round-trip' % encoding
! except ValueError,why:
! print '*** codec for "%s" failed: %s' % (encoding, why)
!
! print 'done.'
!
! print 'Testing Unicode string concatenation...',
! assert (u"abc" u"def") == u"abcdef"
! assert ("abc" u"def") == u"abcdef"
! assert (u"abc" "def") == u"abcdef"
! assert (u"abc" u"def" "ghi") == u"abcdefghi"
! assert ("abc" "def" u"ghi") == u"abcdefghi"
print 'done.'
--- 5,50 ----
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
! """#"
from test_support import verbose
import sys
! # Test Unicode database APIs
! import unicodedata
!
! print 'Testing unicodedata module...',
!
! assert unicodedata.digit(u'A',None) is None
! assert unicodedata.digit(u'9') == 9
! assert unicodedata.digit(u'\u215b',None) is None
! assert unicodedata.digit(u'\u2468') == 9
!
! assert unicodedata.numeric(u'A',None) is None
! assert unicodedata.numeric(u'9') == 9
! assert unicodedata.numeric(u'\u215b') == 0.125
! assert unicodedata.numeric(u'\u2468') == 9.0
!
! assert unicodedata.decimal(u'A',None) is None
! assert unicodedata.decimal(u'9') == 9
! assert unicodedata.decimal(u'\u215b',None) is None
! assert unicodedata.decimal(u'\u2468',None) is None
!
! assert unicodedata.category(u'\uFFFE') == 'Cn'
! assert unicodedata.category(u'a') == 'Ll'
! assert unicodedata.category(u'A') == 'Lu'
!
! assert unicodedata.bidirectional(u'\uFFFE') == ''
! assert unicodedata.bidirectional(u' ') == 'WS'
! assert unicodedata.bidirectional(u'A') == 'L'
!
! assert unicodedata.decomposition(u'\uFFFE') == ''
! assert unicodedata.decomposition(u'\u00bc') == '<fraction> 0031 2044 0034'
!
! assert unicodedata.mirrored(u'\uFFFE') == 0
! assert unicodedata.mirrored(u'a') == 0
! assert unicodedata.mirrored(u'\u2201') == 1
!
! assert unicodedata.combining(u'\uFFFE') == 0
! assert unicodedata.combining(u'a') == 0
! assert unicodedata.combining(u'\u20e1') == 230
!
print 'done.'
Index: test_win.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dos-8x3/test_win.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -r1.1 -r1.1.2.1
*** test_win.py 2000/05/08 17:31:03 1.1
--- test_win.py 2000/09/03 16:06:27 1.1.2.1
***************
*** 2,6 ****
# Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
! from winreg import *
import os, sys
--- 2,6 ----
# Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
! from _winreg import *
import os, sys
***************
*** 43,63 ****
CloseKey(sub_key)
try:
! QueryInfoKey(int_sub_key)
! raise RuntimeError, "It appears the CloseKey() function does not close the actual key!"
except EnvironmentError:
! pass
# ... and close that key that way :-)
int_key = int(key)
key.Close()
try:
! QueryInfoKey(int_key)
! raise RuntimeError, "It appears the key.Close() function does not close the actual key!"
except EnvironmentError:
! pass
def ReadTestData(root_key):
# Check we can get default value for this key.
val = QueryValue(root_key, test_key_name)
! assert val=="Default value", "Registry didnt give back the correct value"
key = OpenKey(root_key, test_key_name)
--- 43,63 ----
CloseKey(sub_key)
try:
! QueryInfoKey(int_sub_key)
! raise RuntimeError, "It appears the CloseKey() function does not close the actual key!"
except EnvironmentError:
! pass
# ... and close that key that way :-)
int_key = int(key)
key.Close()
try:
! QueryInfoKey(int_key)
! raise RuntimeError, "It appears the key.Close() function does not close the actual key!"
except EnvironmentError:
! pass
def ReadTestData(root_key):
# Check we can get default value for this key.
val = QueryValue(root_key, test_key_name)
! assert val=="Default value", "Registry didn't give back the correct value"
key = OpenKey(root_key, test_key_name)
***************
*** 71,77 ****
except EnvironmentError:
break
! assert data in test_data, "didnt read back the correct test data."
index = index + 1
! assert index==len(test_data), "Didnt read the correct number of items"
# Check I can directly access each item
for value_name, value_data, value_type in test_data:
--- 71,77 ----
except EnvironmentError:
break
! assert data in test_data, "Didn't read back the correct test data"
index = index + 1
! assert index==len(test_data), "Didn't read the correct number of items"
# Check I can directly access each item
for value_name, value_data, value_type in test_data:
***************
*** 116,120 ****
try:
key = OpenKey(root_key, test_key_name)
! assert 0, "Could open the non-existant key"
except WindowsError: # Use this error name this time
pass
--- 116,120 ----
try:
key = OpenKey(root_key, test_key_name)
! assert 0, "Could open the non-existent key"
except WindowsError: # Use this error name this time
pass
--- threadst.py DELETED ---