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

the usual

üst 257543c7
This diff is collapsed.
......@@ -23,6 +23,7 @@ SUCCESS = "success"
ANY = "any"
ASSERT = "assert"
ASSERT_NOT = "assert_not"
AT = "at"
BRANCH = "branch"
CALL = "call"
......@@ -81,7 +82,7 @@ OPCODES = [
FAILURE, SUCCESS,
ANY,
ASSERT,
ASSERT, ASSERT_NOT,
AT,
BRANCH,
CALL,
......@@ -121,8 +122,8 @@ def makedict(list):
d = {}
i = 0
for item in list:
d[item] = i
i = i + 1
d[item] = i
i = i + 1
return d
OPCODES = makedict(OPCODES)
......@@ -176,12 +177,27 @@ SRE_FLAG_VERBOSE = 64
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))
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("/* generated from sre_constants.py */\n")
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")
......
This diff is collapsed.
# test the invariant that
# iff a==b then hash(a)==hash(b)
#
import test_support
def same_hash(*objlist):
# hash each object given an raise TestFailed if
# the hash values are not all the same
hashed = map(hash, objlist)
for h in hashed[1:]:
if h != hashed[0]:
raise TestFailed, "hashed values differ: %s" % `objlist`
same_hash(1, 1L, 1.0, 1.0+0.0j)
same_hash(int(1), long(1), float(1), complex(1))
same_hash(long(1.23e300), float(1.23e300))
same_hash(float(0.5), complex(0.5, 0.0))
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