summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_robotparser.py
blob: 666d00ac500bc41031e444d981d16e6de1d09c31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import unittest, StringIO, robotparser
from test import test_support

class RobotTestCase(unittest.TestCase):
    def __init__(self, index, parser, url, good, agent):
        unittest.TestCase.__init__(self)
        if good:
            self.str = "RobotTest(%d, good, %s)" % (index, url)
        else:
            self.str = "RobotTest(%d, bad, %s)" % (index, url)
        self.parser = parser
        self.url = url
        self.good = good
        self.agent = agent

    def runTest(self):
        if isinstance(self.url, tuple):
            agent, url = self.url
        else:
            url = self.url
            agent = self.agent
        if self.good:
            self.failUnless(self.parser.can_fetch(agent, url))
        else:
            self.failIf(self.parser.can_fetch(agent, url))

    def __str__(self):
        return self.str

tests = unittest.TestSuite()

def RobotTest(index, robots_txt, good_urls, bad_urls,
              agent="test_robotparser"):

    lines = StringIO.StringIO(robots_txt).readlines()
    parser = robotparser.RobotFileParser()
    parser.parse(lines)
    for url in good_urls:
        tests.addTest(RobotTestCase(index, parser, url, 1, agent))
    for url in bad_urls:
        tests.addTest(RobotTestCase(index, parser, url, 0, agent))

# Examples from http://www.robotstxt.org/wc/norobots.html (fetched 2002)

# 1.
doc = """
User-agent: *
Disallow: /cyberworld/map/ # This is an infinite virtual URL space
Disallow: /tmp/ # these will soon disappear
Disallow: /foo.html
"""

good = ['/','/test.html']
bad = ['/cyberworld/map/index.html','/tmp/xxx','/foo.html']

RobotTest(1, doc, good, bad)

# 2.
doc = """
# robots.txt for http://www.example.com/

User-agent: *
Disallow: /cyberworld/map/ # This is an infinite virtual URL space

# Cybermapper knows where to go.
User-agent: cybermapper
Disallow:

"""

good = ['/','/test.html',('cybermapper','/cyberworld/map/index.html')]
bad = ['/cyberworld/map/index.html']

RobotTest(2, doc, good, bad)

# 3.
doc = """
# go away
User-agent: *
Disallow: /
"""

good = []
bad = ['/cyberworld/map/index.html','/','/tmp/']

RobotTest(3, doc, good, bad)

# Examples from http://www.robotstxt.org/wc/norobots-rfc.html (fetched 2002)

# 4.
doc = """
User-agent: figtree
Disallow: /tmp
Disallow: /a%3cd.html
Disallow: /a%2fb.html
Disallow: /%7ejoe/index.html
"""

good = [] # XFAIL '/a/b.html'
bad = ['/tmp','/tmp.html','/tmp/a.html',
       '/a%3cd.html','/a%3Cd.html','/a%2fb.html',
       '/~joe/index.html'
       ]

RobotTest(4, doc, good, bad, 'figtree')
RobotTest(5, doc, good, bad, 'FigTree Robot libwww-perl/5.04')

# 6.
doc = """
User-agent: *
Disallow: /tmp/
Disallow: /a%3Cd.html
Disallow: /a/b.html
Disallow: /%7ejoe/index.html
"""

good = ['/tmp',] # XFAIL: '/a%2fb.html'
bad = ['/tmp/','/tmp/a.html',
       '/a%3cd.html','/a%3Cd.html',"/a/b.html",
       '/%7Ejoe/index.html']

RobotTest(6, doc, good, bad)

# From bug report #523041

# 7.
doc = """
User-Agent: *
Disallow: /.
"""

good = ['/foo.html']
bad = [] # Bug report says "/" should be denied, but that is not in the RFC

RobotTest(7, doc, good, bad)

def test_main():
    test_support.run_unittest(tests)

if __name__=='__main__':
    test_support.Verbose = 1
    test_main()
/Tkinter.py b/Lib/lib-tk/Tkinter.py index ef588e8..144be0a 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -1688,8 +1688,8 @@ class Tk(Misc, Wm): _default_root = None def readprofile(self, baseName, className): """Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into - the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if - such a file exists in the home directory.""" + the Tcl Interpreter and calls exec on the contents of BASENAME.py and + CLASSNAME.py if such a file exists in the home directory.""" import os if 'HOME' in os.environ: home = os.environ['HOME'] else: home = os.curdir @@ -1702,11 +1702,11 @@ class Tk(Misc, Wm): if os.path.isfile(class_tcl): self.tk.call('source', class_tcl) if os.path.isfile(class_py): - execfile(class_py, dir) + exec(open(class_py).read(), dir) if os.path.isfile(base_tcl): self.tk.call('source', base_tcl) if os.path.isfile(base_py): - execfile(base_py, dir) + exec(open(base_py).read(), dir) def report_callback_exception(self, exc, val, tb): """Internal function. It reports exception on sys.stderr.""" import traceback, sys diff --git a/Lib/optparse.py b/Lib/optparse.py index 84a6abd..bae1050 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -874,7 +874,7 @@ class Values: def read_file(self, filename, mode="careful"): vars = {} - execfile(filename, vars) + exec(open(filename).read(), vars) self._update(vars, mode) def ensure_value(self, attr, value): diff --git a/Lib/pdb.py b/Lib/pdb.py index f408bf3..3bbf76b 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1164,7 +1164,12 @@ see no sign that the breakpoint was reached. self._wait_for_mainpyfile = 1 self.mainpyfile = self.canonic(filename) self._user_requested_quit = 0 - statement = 'execfile( "%s")' % filename + fp = open(filename) + try: + script = fp.read() + finally: + fp.close() + statement = 'exec("%s")' % script self.run(statement) # Simplified interface diff --git a/Lib/plat-mac/appletrawmain.py b/Lib/plat-mac/appletrawmain.py index 6f2eacb..5c09e2d 100644 --- a/Lib/plat-mac/appletrawmain.py +++ b/Lib/plat-mac/appletrawmain.py @@ -41,7 +41,7 @@ if os.path.exists(__file__): # sys.argv[0] = __file__ del argvemulator, os, sys, _dir - execfile(__file__) + exec(open(__file__).read()) else: __file__ = os.path.join(_dir, '__main__.pyc') if os.path.exists(__file__): diff --git a/Lib/plat-mac/bundlebuilder.py b/Lib/plat-mac/bundlebuilder.py index e833add..d8186c1 100755 --- a/Lib/plat-mac/bundlebuilder.py +++ b/Lib/plat-mac/bundlebuilder.py @@ -322,7 +322,12 @@ ARGV_EMULATOR = """\ import argvemulator, os argvemulator.ArgvCollector().mainloop() -execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s")) +fp = os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s") +try: + script = fp.read() +finally: + fp.close() +exec(script) """ # diff --git a/Lib/profile.py b/Lib/profile.py index 55118b5..cdc2479 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -609,7 +609,12 @@ def main(): if (len(sys.argv) > 0): sys.path.insert(0, os.path.dirname(sys.argv[0])) - run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort) + fp = open(sys.argv[0]) + try: + script = fp.read() + finally: + fp.close() + run('exec(%r)' % script, options.outfile, options.sort) else: parser.print_usage() return parser diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index a4ae21a..b430822 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -11,10 +11,6 @@ warnings.filterwarnings("ignore", "hex../oct.. of negative int", warnings.filterwarnings("ignore", "integer argument expected", DeprecationWarning, "unittest") -# count the number of test runs. -# used to skip running test_execfile() multiple times -numruns = 0 - class Squares: def __init__(self, max): @@ -399,57 +395,6 @@ class BuiltinTest(unittest.TestCase): return 1 # used to be 'a' but that's no longer an error self.assertRaises(TypeError, eval, 'dir()', globals(), C()) - # Done outside of the method test_z to get the correct scope - z = 0 - f = open(TESTFN, 'w') - f.write('z = z+1\n') - f.write('z = z*2\n') - f.close() - execfile(TESTFN) - - def test_execfile(self): - global numruns - if numruns: - return - numruns += 1 - - globals = {'a': 1, 'b': 2} - locals = {'b': 200, 'c': 300} - - self.assertEqual(self.__class__.z, 2) - globals['z'] = 0 - execfile(TESTFN, globals) - self.assertEqual(globals['z'], 2) - locals['z'] = 0 - execfile(TESTFN, globals, locals) - self.assertEqual(locals['z'], 2) - - class M: - "Test mapping interface versus possible calls from execfile()." - def __init__(self): - self.z = 10 - def __getitem__(self, key): - if key == 'z': - return self.z - raise KeyError - def __setitem__(self, key, value): - if key == 'z': - self.z = value - return - raise KeyError - - locals = M() - locals['z'] = 0 - execfile(TESTFN, globals, locals) - self.assertEqual(locals['z'], 2) - - unlink(TESTFN) - self.assertRaises(TypeError, execfile) - self.assertRaises(TypeError, execfile, TESTFN, {}, ()) - import os - self.assertRaises(IOError, execfile, os.curdir) - self.assertRaises(IOError, execfile, "I_dont_exist") - def test_exec(self): g = {} exec('z = 1', g) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index 32c48fb..c2f34e5 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -49,7 +49,7 @@ class Test_MultibyteCodec(unittest.TestCase): try: for enc in ALL_CJKENCODINGS: print('# coding:', enc, file=io.open(TESTFN, 'w')) - execfile(TESTFN) + exec(open(TESTFN).read()) finally: test_support.unlink(TESTFN) diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index 1a3f2a9..907359b 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -63,7 +63,7 @@ def runtest(hier, code): sys.path.insert(0, root) if verbose: print("sys.path =", sys.path) try: - execfile(fname, globals(), {}) + exec(open(fname).read(), globals(), {}) except: traceback.print_exc(file=sys.stdout) finally: diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index ae4c442..7810cae 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -78,13 +78,6 @@ class TestGenericUnivNewlines(unittest.TestCase): data = fp.readlines() self.assertEqual(data, DATA_SPLIT[1:]) - def test_execfile(self): - namespace = {} - execfile(test_support.TESTFN, namespace) - func = namespace['line3'] - self.assertEqual(func.__code__.co_firstlineno, 3) - self.assertEqual(namespace['line4'], FATX) - class TestNativeNewlines(TestGenericUnivNewlines): NEWLINE = None diff --git a/Lib/trace.py b/Lib/trace.py index d40f13c..645517a 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -773,7 +773,12 @@ def main(argv=None): ignoredirs=ignore_dirs, infile=counts_file, outfile=counts_file) try: - t.run('execfile(%r)' % (progname,)) + fp = open(progname) + try: + script = fp.read() + finally: + fp.close() + t.run('exec(%r)' % (script,)) except IOError as err: _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) except SystemExit: diff --git a/Lib/user.py b/Lib/user.py index e550e52..99efd2d 100644 --- a/Lib/user.py +++ b/Lib/user.py @@ -12,7 +12,7 @@ that wishes to use the mechanism must execute the statement import user The user module looks for a file .pythonrc.py in the user's home -directory and if it can be opened, execfile()s it in its own global +directory and if it can be opened and read, exec()s it in its own global namespace. Errors during this phase are not caught; that's up to the program that imports the user module, if it wishes. @@ -42,4 +42,4 @@ except IOError: pass else: f.close() - execfile(pythonrc) + exec(open(pythonrc).read()) diff --git a/Mac/Modules/ae/aescan.py b/Mac/Modules/ae/aescan.py index 1283c1d..0ea367c 100644 --- a/Mac/Modules/ae/aescan.py +++ b/Mac/Modules/ae/aescan.py @@ -21,7 +21,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done Scanning and Generating, now doing 'import aesupport' ===" import aesupport print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ===" diff --git a/Mac/Modules/ae/aesupport.py b/Mac/Modules/ae/aesupport.py index 91c5b82..d3e1dfd 100644 --- a/Mac/Modules/ae/aesupport.py +++ b/Mac/Modules/ae/aesupport.py @@ -213,8 +213,8 @@ module.addobject(aedescobject) functions = [] aedescmethods = [] -execfile('aegen.py') -##execfile('aedatamodelgen.py') +exec(open('aegen.py').read()) +##exec(open('aedatamodelgen.py').read()) # Manual generator AutoDispose_body = """ diff --git a/Mac/Modules/ah/ahscan.py b/Mac/Modules/ah/ahscan.py index 0b7fe08..8768b60 100644 --- a/Mac/Modules/ah/ahscan.py +++ b/Mac/Modules/ah/ahscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/ah/ahsupport.py b/Mac/Modules/ah/ahsupport.py index c5f24be..9fa9dde 100644 --- a/Mac/Modules/ah/ahsupport.py +++ b/Mac/Modules/ah/ahsupport.py @@ -34,7 +34,7 @@ Function = OSErrFunctionGenerator # Create and populate the lists functions = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/app/appscan.py b/Mac/Modules/app/appscan.py index 1b04859..246d61e 100644 --- a/Mac/Modules/app/appscan.py +++ b/Mac/Modules/app/appscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/app/appsupport.py b/Mac/Modules/app/appsupport.py index 177dfd5..73f5f11 100644 --- a/Mac/Modules/app/appsupport.py +++ b/Mac/Modules/app/appsupport.py @@ -121,7 +121,7 @@ Function = OSErrWeakLinkFunctionGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/carbonevt/CarbonEvtscan.py b/Mac/Modules/carbonevt/CarbonEvtscan.py index e3c72ae..7307327 100644 --- a/Mac/Modules/carbonevt/CarbonEvtscan.py +++ b/Mac/Modules/carbonevt/CarbonEvtscan.py @@ -20,7 +20,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "--done scanning, importing--" import CarbonEvtsupport print "done" diff --git a/Mac/Modules/carbonevt/CarbonEvtsupport.py b/Mac/Modules/carbonevt/CarbonEvtsupport.py index 77d12b6..2adc8cb 100644 --- a/Mac/Modules/carbonevt/CarbonEvtsupport.py +++ b/Mac/Modules/carbonevt/CarbonEvtsupport.py @@ -214,7 +214,7 @@ for typ in RefObjectTypes: ## go thru all ObjectTypes as defined in CarbonEvents execstr = typ + 'methods = []' exec execstr -execfile('CarbonEventsgen.py') +exec(open('CarbonEventsgen.py').read()) diff --git a/Mac/Modules/cf/cfscan.py b/Mac/Modules/cf/cfscan.py index d2de92e..5ff9534 100644 --- a/Mac/Modules/cf/cfscan.py +++ b/Mac/Modules/cf/cfscan.py @@ -45,7 +45,7 @@ def main(): scanner.gentypetest(SHORT+"typetest.py") scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/cf/cfsupport.py b/Mac/Modules/cf/cfsupport.py index 800581a..655331e 100644 --- a/Mac/Modules/cf/cfsupport.py +++ b/Mac/Modules/cf/cfsupport.py @@ -529,7 +529,7 @@ CFMutableStringRef_methods = [] CFURLRef_methods = [] # ADD _methods initializer here -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups diff --git a/Mac/Modules/cg/cgscan.py b/Mac/Modules/cg/cgscan.py index b2e7946..82f4919 100755 --- a/Mac/Modules/cg/cgscan.py +++ b/Mac/Modules/cg/cgscan.py @@ -23,7 +23,7 @@ def main(): scanner.gentypetest(SHORT+"typetest.py") scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/cg/cgsupport.py b/Mac/Modules/cg/cgsupport.py index 6eedfbe..7fa06e2 100755 --- a/Mac/Modules/cg/cgsupport.py +++ b/Mac/Modules/cg/cgsupport.py @@ -145,7 +145,7 @@ Method = MethodGenerator CGContextRef_methods = [] # ADD _methods initializer here -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # manual method, lives in Quickdraw.h f = Method(void, 'SyncCGContextOriginWithPort', diff --git a/Mac/Modules/cm/cmscan.py b/Mac/Modules/cm/cmscan.py index 087f239..1a1e46d 100644 --- a/Mac/Modules/cm/cmscan.py +++ b/Mac/Modules/cm/cmscan.py @@ -17,7 +17,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/cm/cmsupport.py b/Mac/Modules/cm/cmsupport.py index 4109dba..1653bb3 100644 --- a/Mac/Modules/cm/cmsupport.py +++ b/Mac/Modules/cm/cmsupport.py @@ -112,7 +112,7 @@ Method = OSErrWeakLinkMethodGenerator functions = [] c_methods = [] ci_methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/ctl/ctlscan.py b/Mac/Modules/ctl/ctlscan.py index 25333f1..dd74d23 100644 --- a/Mac/Modules/ctl/ctlscan.py +++ b/Mac/Modules/ctl/ctlscan.py @@ -15,7 +15,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now doing 'import ctlsupport' ===" import ctlsupport print "=== Done. It's up to you to compile Ctlmodule.c ===" diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py index d354d94..04fac8b 100644 --- a/Mac/Modules/ctl/ctlsupport.py +++ b/Mac/Modules/ctl/ctlsupport.py @@ -507,8 +507,8 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) -execfile('ctledit.py') +exec(open(INPUTFILE).read()) +exec(open('ctledit.py').read()) # add the populated lists to the generator groups for f in functions: module.add(f) diff --git a/Mac/Modules/dlg/dlgscan.py b/Mac/Modules/dlg/dlgscan.py index 7fb68f7..bf37129 100644 --- a/Mac/Modules/dlg/dlgscan.py +++ b/Mac/Modules/dlg/dlgscan.py @@ -19,7 +19,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py index fa1442e..fcff5c0 100644 --- a/Mac/Modules/dlg/dlgsupport.py +++ b/Mac/Modules/dlg/dlgsupport.py @@ -240,7 +240,7 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile("dlggen.py") +exec(open("dlggen.py").read()) # add the populated lists to the generator groups for f in functions: module.add(f) diff --git a/Mac/Modules/drag/dragscan.py b/Mac/Modules/drag/dragscan.py index 923a56b..e89897a 100644 --- a/Mac/Modules/drag/dragscan.py +++ b/Mac/Modules/drag/dragscan.py @@ -26,7 +26,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now doing 'import dragsupport' ===" import dragsupport print "=== Done. It's up to you to compile Dragmodule.c ===" diff --git a/Mac/Modules/drag/dragsupport.py b/Mac/Modules/drag/dragsupport.py index 45838ef..bb1a918 100644 --- a/Mac/Modules/drag/dragsupport.py +++ b/Mac/Modules/drag/dragsupport.py @@ -216,7 +216,7 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups for f in functions: module.add(f) diff --git a/Mac/Modules/evt/evtscan.py b/Mac/Modules/evt/evtscan.py index 0d0c9ec..0adce8b 100644 --- a/Mac/Modules/evt/evtscan.py +++ b/Mac/Modules/evt/evtscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/evt/evtsupport.py b/Mac/Modules/evt/evtsupport.py index f58da14..8deef92 100644 --- a/Mac/Modules/evt/evtsupport.py +++ b/Mac/Modules/evt/evtsupport.py @@ -50,7 +50,7 @@ Function = OSErrWeakLinkFunctionGenerator # Create and populate the lists functions = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # Move TickCount here, for convenience f = Function(UInt32, 'TickCount', diff --git a/Mac/Modules/file/filescan.py b/Mac/Modules/file/filescan.py index 8ebc69f..b7c5d12 100644 --- a/Mac/Modules/file/filescan.py +++ b/Mac/Modules/file/filescan.py @@ -18,7 +18,7 @@ def main(): scanner.close() scanner.gentypetest(SHORT+"typetest.py") print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py index 37aeb50..de45ed4 100644 --- a/Mac/Modules/file/filesupport.py +++ b/Mac/Modules/file/filesupport.py @@ -340,7 +340,7 @@ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec); PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef); """ -execfile(string.lower(MODPREFIX) + 'typetest.py') +exec(open(string.lower(MODPREFIX) + 'typetest.py').read()) # Our object types: class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition): @@ -806,7 +806,7 @@ functions = [] alias_methods = [] fsref_methods = [] fsspec_methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # Manual generators: FSRefMakePath_body = """ diff --git a/Mac/Modules/fm/fmscan.py b/Mac/Modules/fm/fmscan.py index 334d5ec..38abcac 100644 --- a/Mac/Modules/fm/fmscan.py +++ b/Mac/Modules/fm/fmscan.py @@ -17,7 +17,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/fm/fmsupport.py b/Mac/Modules/fm/fmsupport.py index e692053..8e2b8b3 100644 --- a/Mac/Modules/fm/fmsupport.py +++ b/Mac/Modules/fm/fmsupport.py @@ -70,7 +70,7 @@ Function = OSErrWeakLinkFunctionGenerator # Create and populate the lists functions = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/folder/folderscan.py b/Mac/Modules/folder/folderscan.py index 8c94893..cccb720 100644 --- a/Mac/Modules/folder/folderscan.py +++ b/Mac/Modules/folder/folderscan.py @@ -19,7 +19,7 @@ def main(): scanner.close() scanner.gentypetest(SHORT+"typetest.py") print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/folder/foldersupport.py b/Mac/Modules/folder/foldersupport.py index b9b64bf..224b545 100644 --- a/Mac/Modules/folder/foldersupport.py +++ b/Mac/Modules/folder/foldersupport.py @@ -33,7 +33,7 @@ includestuff = includestuff + """ """ -execfile(string.lower(MODPREFIX) + 'typetest.py') +exec(open(string.lower(MODPREFIX) + 'typetest.py').read()) # From here on it's basically all boiler plate... @@ -45,7 +45,7 @@ Function = OSErrFunctionGenerator # Create and populate the lists functions = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/help/helpscan.py b/Mac/Modules/help/helpscan.py index 50e0919..fa8dbde 100644 --- a/Mac/Modules/help/helpscan.py +++ b/Mac/Modules/help/helpscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/help/helpsupport.py b/Mac/Modules/help/helpsupport.py index 77f5c2e..37117ee 100644 --- a/Mac/Modules/help/helpsupport.py +++ b/Mac/Modules/help/helpsupport.py @@ -66,7 +66,7 @@ Function = OSErrFunctionGenerator # Create and populate the lists functions = [] ##methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/ibcarbon/IBCarbonscan.py b/Mac/Modules/ibcarbon/IBCarbonscan.py index 84e4f1e..eb7267d 100644 --- a/Mac/Modules/ibcarbon/IBCarbonscan.py +++ b/Mac/Modules/ibcarbon/IBCarbonscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "--done scanning, importing--" import IBCarbonsupport print "done" diff --git a/Mac/Modules/ibcarbon/IBCarbonsupport.py b/Mac/Modules/ibcarbon/IBCarbonsupport.py index 5f41328..8744b69 100644 --- a/Mac/Modules/ibcarbon/IBCarbonsupport.py +++ b/Mac/Modules/ibcarbon/IBCarbonsupport.py @@ -42,7 +42,7 @@ module.addobject(ibnibobject) functions = [] methods = [] -execfile('IBCarbongen.py') +exec(open('IBCarbongen.py').read()) for f in functions: module.add(f) for m in methods: ibnibobject.add(m) diff --git a/Mac/Modules/icn/icnscan.py b/Mac/Modules/icn/icnscan.py index bdc3b84..2d20062 100644 --- a/Mac/Modules/icn/icnscan.py +++ b/Mac/Modules/icn/icnscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/icn/icnsupport.py b/Mac/Modules/icn/icnsupport.py index 1b15385..e9a8b78 100644 --- a/Mac/Modules/icn/icnsupport.py +++ b/Mac/Modules/icn/icnsupport.py @@ -78,7 +78,7 @@ Function = OSErrWeakLinkFunctionGenerator # Create and populate the lists functions = [] ##methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/launch/launchscan.py b/Mac/Modules/launch/launchscan.py index 621033b..dd43e37 100644 --- a/Mac/Modules/launch/launchscan.py +++ b/Mac/Modules/launch/launchscan.py @@ -19,7 +19,7 @@ def main(): scanner.close() scanner.gentypetest(SHORT+"typetest.py") print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/launch/launchsupport.py b/Mac/Modules/launch/launchsupport.py index 34c2efb..5faf4b3 100644 --- a/Mac/Modules/launch/launchsupport.py +++ b/Mac/Modules/launch/launchsupport.py @@ -75,7 +75,7 @@ LSItemInfoRecord_New(LSItemInfoRecord *it) """ # From here on it's basically all boiler plate... -execfile(string.lower(MODPREFIX) + 'typetest.py') +exec(open(string.lower(MODPREFIX) + 'typetest.py').read()) # Create the generator groups and link them module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) @@ -89,7 +89,7 @@ Function = OSErrFunctionGenerator # Create and populate the lists functions = [] ##methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/list/listscan.py b/Mac/Modules/list/listscan.py index 877f6cb..14e7dca 100644 --- a/Mac/Modules/list/listscan.py +++ b/Mac/Modules/list/listscan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/list/listsupport.py b/Mac/Modules/list/listsupport.py index 93baede..2e1144a 100644 --- a/Mac/Modules/list/listsupport.py +++ b/Mac/Modules/list/listsupport.py @@ -169,7 +169,7 @@ Method = ListMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # Function to convert any handle to a list and vv. ##f = Function(ListHandle, 'as_List', (Handle, 'h', InMode)) diff --git a/Mac/Modules/menu/menuscan.py b/Mac/Modules/menu/menuscan.py index ae9465e..46afe16 100644 --- a/Mac/Modules/menu/menuscan.py +++ b/Mac/Modules/menu/menuscan.py @@ -14,7 +14,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now doing 'import menusupport' ===" import menusupport print "=== Done. It's up to you to compile Menumodule.c ===" diff --git a/Mac/Modules/menu/menusupport.py b/Mac/Modules/menu/menusupport.py index a04b755..93d489b 100644 --- a/Mac/Modules/menu/menusupport.py +++ b/Mac/Modules/menu/menusupport.py @@ -96,8 +96,8 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) -execfile(EXTRAFILE) +exec(open(INPUTFILE).read()) +exec(open(EXTRAFILE).read()) # add the populated lists to the generator groups for f in functions: module.add(f) diff --git a/Mac/Modules/mlte/mltescan.py b/Mac/Modules/mlte/mltescan.py index adecb4f..9566ad7 100644 --- a/Mac/Modules/mlte/mltescan.py +++ b/Mac/Modules/mlte/mltescan.py @@ -20,7 +20,7 @@ def main(): scanner.gentypetest(SHORT+"typetest.py") scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/mlte/mltesupport.py b/Mac/Modules/mlte/mltesupport.py index 8dcbed5..4adde0d 100644 --- a/Mac/Modules/mlte/mltesupport.py +++ b/Mac/Modules/mlte/mltesupport.py @@ -128,7 +128,7 @@ OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr") UniChar = Type("UniChar", "h") # XXXX For now... # ADD object type here -execfile("mltetypetest.py") +exec(open("mltetypetest.py").read()) # Our (opaque) objects @@ -166,7 +166,7 @@ TXNObject_methods = [] TXNFontMenuObject_methods = [] # ADD _methods initializer here -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups diff --git a/Mac/Modules/osa/osascan.py b/Mac/Modules/osa/osascan.py index fb8196f..8bad4b7 100644 --- a/Mac/Modules/osa/osascan.py +++ b/Mac/Modules/osa/osascan.py @@ -18,7 +18,7 @@ def main(): scanner.close() scanner.gentypetest(SHORT+"typetest.py") print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/osa/osasupport.py b/Mac/Modules/osa/osasupport.py index 8369932..3afdf4e 100644 --- a/Mac/Modules/osa/osasupport.py +++ b/Mac/Modules/osa/osasupport.py @@ -88,12 +88,12 @@ Function = OSErrWeakLinkFunctionGenerator Method = OSErrWeakLinkMethodGenerator # Test which types we are still missing. -execfile(string.lower(MODPREFIX) + 'typetest.py') +exec(open(string.lower(MODPREFIX) + 'typetest.py').read()) # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/qd/qdscan.py b/Mac/Modules/qd/qdscan.py index 85a8cdc..c601b0e 100644 --- a/Mac/Modules/qd/qdscan.py +++ b/Mac/Modules/qd/qdscan.py @@ -41,7 +41,7 @@ def main(): ofp.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" import qdsupport print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py index d078ac6..28c2595 100644 --- a/Mac/Modules/qd/qdsupport.py +++ b/Mac/Modules/qd/qdsupport.py @@ -269,8 +269,8 @@ functions = [] gr_methods = [] bm_methods = [] #methods = [] -execfile(INPUTFILE) -execfile(EXTRAFILE) +exec(open(INPUTFILE).read()) +exec(open(EXTRAFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/qdoffs/qdoffsscan.py b/Mac/Modules/qdoffs/qdoffsscan.py index d456e00..7e8f316 100644 --- a/Mac/Modules/qdoffs/qdoffsscan.py +++ b/Mac/Modules/qdoffs/qdoffsscan.py @@ -14,7 +14,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" import qdoffssupport print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/qdoffs/qdoffssupport.py b/Mac/Modules/qdoffs/qdoffssupport.py index 1617773..73855a2 100644 --- a/Mac/Modules/qdoffs/qdoffssupport.py +++ b/Mac/Modules/qdoffs/qdoffssupport.py @@ -86,7 +86,7 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # A method to convert a GWorldPtr to a GrafPtr f = Method(GrafPtr, 'as_GrafPtr', (GWorldPtr, 'p', InMode)) diff --git a/Mac/Modules/qt/qtscan.py b/Mac/Modules/qt/qtscan.py index a2dba15..ac56144 100644 --- a/Mac/Modules/qt/qtscan.py +++ b/Mac/Modules/qt/qtscan.py @@ -35,7 +35,7 @@ def main(): scanner.close() scanner.gentypetest(SHORT+"typetest.py") print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/qt/qtsupport.py b/Mac/Modules/qt/qtsupport.py index 132c2b4..4d7988f 100644 --- a/Mac/Modules/qt/qtsupport.py +++ b/Mac/Modules/qt/qtsupport.py @@ -307,7 +307,7 @@ module.addobject(Movie_object) module.addobject(SGOutput_object) # Test which types we are still missing. -execfile(string.lower(MODPREFIX) + 'typetest.py') +exec(open(string.lower(MODPREFIX) + 'typetest.py').read()) # Create the generator classes used to populate the lists Function = OSErrWeakLinkFunctionGenerator @@ -323,7 +323,7 @@ Media_methods = [] Track_methods = [] Movie_methods = [] SGOutput_methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # # Some functions from ImageCompression.h that we need: diff --git a/Mac/Modules/res/resscan.py b/Mac/Modules/res/resscan.py index 47a97e4..853fa13 100644 --- a/Mac/Modules/res/resscan.py +++ b/Mac/Modules/res/resscan.py @@ -20,7 +20,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now doing 'import ressupport' ===" import ressupport print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ===" diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py index 9e42a45..4eed9ec 100644 --- a/Mac/Modules/res/ressupport.py +++ b/Mac/Modules/res/ressupport.py @@ -211,8 +211,8 @@ module.addobject(resobject) functions = [] resmethods = [] -execfile('resgen.py') -execfile('resedit.py') +exec(open('resgen.py').read()) +exec(open('resedit.py').read()) for f in functions: module.add(f) for f in resmethods: resobject.add(f) diff --git a/Mac/Modules/scrap/scrapscan.py b/Mac/Modules/scrap/scrapscan.py index 1fc8191..7521fba 100644 --- a/Mac/Modules/scrap/scrapscan.py +++ b/Mac/Modules/scrap/scrapscan.py @@ -20,7 +20,7 @@ def main(): scanner.scan() scanner.close() ## print "=== Testing definitions output code ===" -## execfile(defsoutput, {}, {}) +## exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/scrap/scrapsupport.py b/Mac/Modules/scrap/scrapsupport.py index 84a75d2..b4226a5 100644 --- a/Mac/Modules/scrap/scrapsupport.py +++ b/Mac/Modules/scrap/scrapsupport.py @@ -63,7 +63,7 @@ Method = OSErrMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Mac/Modules/snd/sndscan.py b/Mac/Modules/snd/sndscan.py index c4a8266..bcdd062 100644 --- a/Mac/Modules/snd/sndscan.py +++ b/Mac/Modules/snd/sndscan.py @@ -17,7 +17,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now doing 'import sndsupport' ===" import sndsupport print "=== Done. It's up to you to compile Sndmodule.c ===" diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py index cf0fa6c..5c5da54 100644 --- a/Mac/Modules/snd/sndsupport.py +++ b/Mac/Modules/snd/sndsupport.py @@ -304,7 +304,7 @@ sndmethods = [] # populate the lists -execfile('sndgen.py') +exec(open('sndgen.py').read()) # add the functions and methods to the module and object, respectively diff --git a/Mac/Modules/te/tescan.py b/Mac/Modules/te/tescan.py index f5b6fff..c0d6e1c 100644 --- a/Mac/Modules/te/tescan.py +++ b/Mac/Modules/te/tescan.py @@ -18,7 +18,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" exec "import " + SHORT + "support" print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/te/tesupport.py b/Mac/Modules/te/tesupport.py index ad6c053..412d5e7 100644 --- a/Mac/Modules/te/tesupport.py +++ b/Mac/Modules/te/tesupport.py @@ -198,7 +198,7 @@ Method = TEMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # Converter from/to handle f = Function(TEHandle, 'as_TE', (Handle, 'h', InMode)) diff --git a/Mac/Modules/win/winscan.py b/Mac/Modules/win/winscan.py index f78935d..8d2cea9 100644 --- a/Mac/Modules/win/winscan.py +++ b/Mac/Modules/win/winscan.py @@ -14,7 +14,7 @@ def main(): scanner.scan() scanner.close() print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) + exec(open(defsoutput).read(), {}, {}) print "=== Done scanning and generating, now importing the generated code... ===" import winsupport print "=== Done. It's up to you to compile it now! ===" diff --git a/Mac/Modules/win/winsupport.py b/Mac/Modules/win/winsupport.py index 08a0379..2cadbdc 100644 --- a/Mac/Modules/win/winsupport.py +++ b/Mac/Modules/win/winsupport.py @@ -191,7 +191,7 @@ Method = OSErrWeakLinkMethodGenerator # Create and populate the lists functions = [] methods = [] -execfile(INPUTFILE) +exec(open(INPUTFILE).read()) # Add manual routines for converting integer WindowPtr's (as returned by # various event routines) and Dialog objects to a WindowObject. @@ -211,8 +211,8 @@ functions.append(f) # And add the routines that access the internal bits of a window struct. They # are currently #defined in Windows.h, they will be real routines in Copland -# (at which time this execfile can go) -execfile(EDITFILE) +# (at which time this exec can go) +exec(open(EDITFILE).read()) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) diff --git a/Misc/NEWS b/Misc/NEWS index 09d1302..b5a67db 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -152,7 +152,7 @@ Core and Builtins backticks (ie, `x`), <> - Removed these Python builtins: - apply(), callable(), coerce(), file(), reduce(), reload() + apply(), callable(), coerce(), execfile(), file(), reduce(), reload() - Removed these Python methods: {}.has_key diff --git a/Misc/Vim/python.vim b/Misc/Vim/python.vim index 3886931..130b699 100644 --- a/Misc/Vim/python.vim +++ b/Misc/Vim/python.vim @@ -66,10 +66,10 @@ if exists("python_highlight_builtins") syn keyword pythonBuiltin __import__ abs all any basestring bool syn keyword pythonBuiltin buffer callable chr classmethod cmp syn keyword pythonBuiltin complex copyright credits delattr dict - syn keyword pythonBuiltin dir divmod enumerate eval execfile exit file + syn keyword pythonBuiltin dir divmod enumerate eval exec exit syn keyword pythonBuiltin filter float frozenset getattr globals hasattr syn keyword pythonBuiltin hash help hex id int isinstance - syn keyword pythonBuiltin issubclass iter len license list locals long map + syn keyword pythonBuiltin issubclass iter len license list locals map syn keyword pythonBuiltin max min object oct open ord pow property quit syn keyword pythonBuiltin range reload repr reversed round syn keyword pythonBuiltin set setattr slice sorted staticmethod str sum diff --git a/Misc/cheatsheet b/Misc/cheatsheet index 3d34471..c530442 100644 --- a/Misc/cheatsheet +++ b/Misc/cheatsheet @@ -282,11 +282,10 @@ None Numeric types -Floats, integers and long integers. +Floats and integers. Floats are implemented with C doubles. - Integers are implemented with C longs. - Long integers have unlimited size (only limit is system resources) + Integers have unlimited size (only limit is system resources) Operators on all numeric types @@ -294,7 +293,6 @@ Operators on all numeric types Operation Result abs(x) the absolute value of x int(x) x converted to integer -long(x) x converted to long integer float(x) x converted to floating point -x x negated +x x unchanged @@ -306,7 +304,7 @@ x % y remainder of x / y divmod(x, y) the tuple (x/y, x%y) x ** y x to the power y (the same as pow(x, y)) -Bit operators on integers and long integers +Bit operators on integers Bit operators Operation >Result @@ -948,9 +946,6 @@ enumerate(seq) Return a iterator giving: (0, seq[0]), (1, seq[1]), ... eval(s[, globals[, Eval string s in (optional) globals, locals contexts.s must locals]]) have no NUL's or newlines. s can also be acode object. Example: x = 1; incr_x = eval('x + 1') -execfile(file[, Executes a file without creating a new module, unlike -globals[, locals]]) import. -file() Synonym for open(). filter(function, Constructs a list from those elements of sequence for which sequence) function returns true. function takes one parameter. float(x) Converts a number or a string to floating point. @@ -977,9 +972,6 @@ len(obj) (sequence, dictionary, or instance of class implementing list(sequence) Converts sequence into a list. If already a list,returns a copy of it. locals() Returns a dictionary containing current local variables. - Converts a number or a string to a long integer. Optional -long(x[, base]) base paramenter specifies base from which to convert string - values. Applies function to every item of list and returns a listof map(function, list, the results. If additional arguments are passed,function ...) must take that many arguments and it is givento function on @@ -1167,7 +1159,7 @@ Operators s^=o = __ixor__(s,o) s|=o = __ior__(s,o) s<<=o = __ilshift__(s,o) s>>=o = __irshift__(s,o) Conversions - int(s) = __int__(s) long(s) = __long__(s) + int(s) = __int__(s) float(s) = __float__(s) complex(s) = __complex__(s) oct(s) = __oct__(s) hex(s) = __hex__(s) Right-hand-side equivalents for all binary operators exist; diff --git a/Misc/python-mode.el b/Misc/python-mode.el index 55ba602..5d9af67 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -380,7 +380,7 @@ support for features needed by `python-mode'.") "bool" "buffer" "callable" "chr" "classmethod" "cmp" "compile" "complex" "copyright" "delattr" "dict" "dir" "divmod" - "enumerate" "eval" "execfile" "exit" "file" + "enumerate" "eval" "exit" "file" "filter" "float" "getattr" "globals" "hasattr" "hash" "hex" "id" "int" "isinstance" "issubclass" "iter" "len" "license" @@ -1262,7 +1262,7 @@ comment." ;; Python subprocess utilities and filters (defun py-execute-file (proc filename) - "Send to Python interpreter process PROC \"execfile('FILENAME')\". + "Send to Python interpreter process PROC \"exec(open('FILENAME').read())\". Make that process's buffer visible and force display. Also make comint believe the user typed this string so that `kill-output-from-shell' does The Right Thing." @@ -1270,7 +1270,7 @@ comint believe the user typed this string so that (procbuf (process-buffer proc)) ; (comint-scroll-to-bottom-on-output t) (msg (format "## working on region in file %s...\n" filename)) - (cmd (format "execfile(r'%s')\n" filename))) + (cmd (format "exec(open(r'%s').read())\n" filename))) (unwind-protect (save-excursion (set-buffer procbuf) @@ -1606,7 +1606,7 @@ specify the region to execute, and optional third argument ASYNC, if non-nil, specifies to run the command asynchronously in its own buffer. -If the Python interpreter shell is running, the region is execfile()'d +If the Python interpreter shell is running, the region is exec()'d in that shell. If you try to execute regions too quickly, `python-mode' will queue them up and execute them one at a time when it sees a `>>> ' prompt from Python. Each time this happens, the @@ -1731,7 +1731,7 @@ subtleties, including the use of the optional ASYNC argument." If the file has already been imported, then do reload instead to get the latest version. -If the file's name does not end in \".py\", then do execfile instead. +If the file's name does not end in \".py\", then do exec instead. If the current buffer is not visiting a file, do `py-execute-buffer' instead. @@ -1768,7 +1768,7 @@ This may be preferable to `\\[py-execute-buffer]' because: (file-name-nondirectory file)))) (format "if globals().has_key('%s'):\n reload(%s)\nelse:\n import %s\n" f f f)) - (format "execfile(r'%s')\n" file)) + (format "exec(open(r'%s'))\n" file)) async)) ;; else (py-execute-buffer async)))) diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 34bca68..8175404 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -317,7 +317,7 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) ** will cause a pause if we're reading from an ** interactive stream, but that is very unlikely ** unless we're doing something silly like - ** execfile("/dev/tty"). + ** exec(open("/dev/tty").read()). */ c = GETC(stream); if ( c != '\n' ) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 2f4e513..b6a7327 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -642,107 +642,6 @@ globals and locals. If only globals is given, locals defaults to it."); static PyObject * -builtin_execfile(PyObject *self, PyObject *args) -{ - char *filename; - PyObject *globals = Py_None, *locals = Py_None; - PyObject *res; - FILE* fp = NULL; - PyCompilerFlags cf; - int exists; - - if (!PyArg_ParseTuple(args, "s|O!O:execfile", - &filename, - &PyDict_Type, &globals, - &locals)) - return NULL; - if (locals != Py_None && !PyMapping_Check(locals)) { - PyErr_SetString(PyExc_TypeError, "locals must be a mapping"); - return NULL; - } - if (globals == Py_None) { - globals = PyEval_GetGlobals(); - if (locals == Py_None) - locals = PyEval_GetLocals(); - } - else if (locals == Py_None) - locals = globals; - if (PyDict_GetItemString(globals, "__builtins__") == NULL) { - if (PyDict_SetItemString(globals, "__builtins__", - PyEval_GetBuiltins()) != 0) - return NULL; - } - - exists = 0; - /* Test for existence or directory. */ -#if defined(PLAN9) - { - Dir *d; - - if ((d = dirstat(filename))!=nil) { - if(d->mode & DMDIR) - werrstr("is a directory"); - else - exists = 1; - free(d); - } - } -#elif defined(RISCOS) - if (object_exists(filename)) { - if (isdir(filename)) - errno = EISDIR; - else - exists = 1; - } -#else /* standard Posix */ - { - struct stat s; - if (stat(filename, &s) == 0) { - if (S_ISDIR(s.st_mode)) -# if defined(PYOS_OS2) && defined(PYCC_VACPP) - errno = EOS2ERR; -# else - errno = EISDIR; -# endif - else - exists = 1; - } - } -#endif - - if (exists) { - Py_BEGIN_ALLOW_THREADS - fp = fopen(filename, "r" PY_STDIOTEXTMODE); - Py_END_ALLOW_THREADS - - if (fp == NULL) { - exists = 0; - } - } - - if (!exists) { - PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename); - return NULL; - } - cf.cf_flags = 0; - if (PyEval_MergeCompilerFlags(&cf)) - res = PyRun_FileExFlags(fp, filename, Py_file_input, globals, - locals, 1, &cf); - else - res = PyRun_FileEx(fp, filename, Py_file_input, globals, - locals, 1); - return res; -} - -PyDoc_STRVAR(execfile_doc, -"execfile(filename[, globals[, locals]])\n\ -\n\ -Read and execute a Python script from a file.\n\ -The globals and locals are dictionaries, defaulting to the current\n\ -globals and locals. If only globals is given, locals defaults to it."); - - -static PyObject * builtin_getattr(PyObject *self, PyObject *args) { PyObject *v, *result, *dflt = NULL, *release = NULL; @@ -1737,7 +1636,6 @@ static PyMethodDef builtin_methods[] = { {"divmod", builtin_divmod, METH_VARARGS, divmod_doc}, {"eval", builtin_eval, METH_VARARGS, eval_doc}, {"exec", builtin_exec, METH_VARARGS, exec_doc}, - {"execfile", builtin_execfile, METH_VARARGS, execfile_doc}, {"filter", builtin_filter, METH_VARARGS, filter_doc}, {"getattr", builtin_getattr, METH_VARARGS, getattr_doc}, {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc}, diff --git a/README b/README index 4fecd7a..ef9f452 100644 --- a/README +++ b/README @@ -1101,7 +1101,7 @@ Modules/getpath.o. --with(out)-universal-newlines: enable reading of tex