Kaydet (Commit) 45f9af34 authored tarafından Christian Heimes's avatar Christian Heimes

Merged revisions 59193-59201 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59195 | facundo.batista | 2007-11-27 19:50:12 +0100 (Tue, 27 Nov 2007) | 4 lines


  Moved the errno import from inside the functions to the
  module level.  Fixes issue 1755179.
........
  r59199 | christian.heimes | 2007-11-27 22:28:40 +0100 (Tue, 27 Nov 2007) | 1 line

  Backport of changes to PCbuild9 from the py3k branch
........
  r59200 | christian.heimes | 2007-11-27 22:34:01 +0100 (Tue, 27 Nov 2007) | 1 line

  Replaced import of the 'new' module with 'types' module and added a deprecation warning to the 'new' module.
........
  r59201 | christian.heimes | 2007-11-27 22:35:44 +0100 (Tue, 27 Nov 2007) | 1 line

  Added a deprecation warning to the 'new' module.
........
üst 1c280ab7
"""Support Eiffel-style preconditions and postconditions.""" """Support Eiffel-style preconditions and postconditions."""
from new import function from types import FunctionType as function
class EiffelBaseMetaClass(type): class EiffelBaseMetaClass(type):
......
...@@ -2010,16 +2010,16 @@ class Tester: ...@@ -2010,16 +2010,16 @@ class Tester:
return (f,t) return (f,t)
def rundict(self, d, name, module=None): def rundict(self, d, name, module=None):
import new import types
m = new.module(name) m = types.ModuleType(name)
m.__dict__.update(d) m.__dict__.update(d)
if module is None: if module is None:
module = False module = False
return self.rundoc(m, name, module) return self.rundoc(m, name, module)
def run__test__(self, d, name): def run__test__(self, d, name):
import new import types
m = new.module(name) m = types.ModuleType(name)
m.__test__ = d m.__test__ = d
return self.rundoc(m, name) return self.rundoc(m, name)
......
...@@ -7,7 +7,7 @@ import imp ...@@ -7,7 +7,7 @@ import imp
import marshal import marshal
import os import os
import sys import sys
import new import types
import struct import struct
if hasattr(sys.__stdout__, "newlines"): if hasattr(sys.__stdout__, "newlines"):
...@@ -589,7 +589,7 @@ class ModuleFinder: ...@@ -589,7 +589,7 @@ class ModuleFinder:
if isinstance(consts[i], type(co)): if isinstance(consts[i], type(co)):
consts[i] = self.replace_paths_in_code(consts[i]) consts[i] = self.replace_paths_in_code(consts[i])
return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize, return types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
co.co_flags, co.co_code, tuple(consts), co.co_names, co.co_flags, co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name, co.co_varnames, new_filename, co.co_name,
co.co_firstlineno, co.co_lnotab, co.co_firstlineno, co.co_lnotab,
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
This module is no longer required except for backward compatibility. This module is no longer required except for backward compatibility.
Objects of most types can now be created by calling the type object. Objects of most types can now be created by calling the type object.
""" """
from warnings import warn as _warn
_warn("The 'new' module is not supported in 3.x, use the 'types' module "
"instead.", DeprecationWarning, 2)
classobj = type classobj = type
from types import FunctionType as function from types import FunctionType as function
......
...@@ -22,7 +22,7 @@ and opendir), and leave all pathname manipulation to os.path ...@@ -22,7 +22,7 @@ and opendir), and leave all pathname manipulation to os.path
#' #'
import sys import sys, errno
_names = sys.builtin_module_names _names = sys.builtin_module_names
...@@ -140,7 +140,6 @@ def makedirs(name, mode=0o777): ...@@ -140,7 +140,6 @@ def makedirs(name, mode=0o777):
recursive. recursive.
""" """
from errno import EEXIST
head, tail = path.split(name) head, tail = path.split(name)
if not tail: if not tail:
head, tail = path.split(head) head, tail = path.split(head)
...@@ -149,7 +148,7 @@ def makedirs(name, mode=0o777): ...@@ -149,7 +148,7 @@ def makedirs(name, mode=0o777):
makedirs(head, mode) makedirs(head, mode)
except OSError as e: except OSError as e:
# be happy if someone already created the path # be happy if someone already created the path
if e.errno != EEXIST: if e.errno != errno.EEXIST:
raise raise
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
return return
...@@ -353,8 +352,6 @@ def execvpe(file, args, env): ...@@ -353,8 +352,6 @@ def execvpe(file, args, env):
__all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"]) __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
def _execvpe(file, args, env=None): def _execvpe(file, args, env=None):
from errno import ENOENT, ENOTDIR
if env is not None: if env is not None:
func = execve func = execve
argrest = (args, env) argrest = (args, env)
...@@ -381,7 +378,7 @@ def _execvpe(file, args, env=None): ...@@ -381,7 +378,7 @@ def _execvpe(file, args, env=None):
except error as e: except error as e:
last_exc = e last_exc = e
tb = sys.exc_info()[2] tb = sys.exc_info()[2]
if (e.errno != ENOENT and e.errno != ENOTDIR if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
and saved_exc is None): and saved_exc is None):
saved_exc = e saved_exc = e
saved_tb = tb saved_tb = tb
......
...@@ -4,7 +4,6 @@ from test.test_support import verify, vereq, verbose, TestFailed, TESTFN ...@@ -4,7 +4,6 @@ from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
from test.test_support import get_original_stdout from test.test_support import get_original_stdout
from copy import deepcopy from copy import deepcopy
import types import types
import new
def veris(a, b): def veris(a, b):
if a is not b: if a is not b:
......
...@@ -448,8 +448,8 @@ docstring, and will recursively explore its contents, including ...@@ -448,8 +448,8 @@ docstring, and will recursively explore its contents, including
functions, classes, and the `__test__` dictionary, if it exists: functions, classes, and the `__test__` dictionary, if it exists:
>>> # A module >>> # A module
>>> import new >>> import types
>>> m = new.module('some_module') >>> m = types.ModuleType('some_module')
>>> def triple(val): >>> def triple(val):
... ''' ... '''
... >>> print(triple(11)) ... >>> print(triple(11))
...@@ -1941,11 +1941,11 @@ def test_DocFileSuite(): ...@@ -1941,11 +1941,11 @@ def test_DocFileSuite():
If DocFileSuite is used from an interactive session, then files If DocFileSuite is used from an interactive session, then files
are resolved relative to the directory of sys.argv[0]: are resolved relative to the directory of sys.argv[0]:
>>> import new, os.path, test.test_doctest >>> import types, os.path, test.test_doctest
>>> save_argv = sys.argv >>> save_argv = sys.argv
>>> sys.argv = [test.test_doctest.__file__] >>> sys.argv = [test.test_doctest.__file__]
>>> suite = doctest.DocFileSuite('test_doctest.txt', >>> suite = doctest.DocFileSuite('test_doctest.txt',
... package=new.module('__main__')) ... package=types.ModuleType('__main__'))
>>> sys.argv = save_argv >>> sys.argv = save_argv
By setting `module_relative=False`, os-specific paths may be By setting `module_relative=False`, os-specific paths may be
...@@ -2370,9 +2370,9 @@ def old_test3(): r""" ...@@ -2370,9 +2370,9 @@ def old_test3(): r"""
""" """
def old_test4(): """ def old_test4(): """
>>> import new >>> import types
>>> m1 = new.module('_m1') >>> m1 = types.ModuleType('_m1')
>>> m2 = new.module('_m2') >>> m2 = types.ModuleType('_m2')
>>> test_data = \""" >>> test_data = \"""
... def _f(): ... def _f():
... '''>>> assert 1 == 1 ... '''>>> assert 1 == 1
......
...@@ -105,11 +105,11 @@ if f2.a.one != f1.a.one != F.a.one != 11: ...@@ -105,11 +105,11 @@ if f2.a.one != f1.a.one != F.a.one != 11:
raise TestFailed raise TestFailed
# __func__ may not be a Python method! # __func__ may not be a Python method!
import new import types
F.id = id F.id = id
eff = F() eff = F()
eff.id = new.instancemethod(id, eff) eff.id = types.MethodType(id, eff)
if eff.id() != id(eff): if eff.id() != id(eff):
raise TestFailed raise TestFailed
......
...@@ -167,8 +167,8 @@ class GetoptTests(unittest.TestCase): ...@@ -167,8 +167,8 @@ class GetoptTests(unittest.TestCase):
['a1', 'a2'] ['a1', 'a2']
""" """
import new import types
m = new.module("libreftest", s) m = types.ModuleType("libreftest", s)
run_doctest(m, verbose) run_doctest(m, verbose)
......
...@@ -213,9 +213,9 @@ class TestRetrievingSourceCode(GetSourceBase): ...@@ -213,9 +213,9 @@ class TestRetrievingSourceCode(GetSourceBase):
self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__) self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
def test_getmodule_recursion(self): def test_getmodule_recursion(self):
from new import module from types import ModuleType
name = '__inspect_dummy' name = '__inspect_dummy'
m = sys.modules[name] = module(name) m = sys.modules[name] = ModuleType(name)
m.__file__ = "<string>" # hopefully not a real filename... m.__file__ = "<string>" # hopefully not a real filename...
m.__loader__ = "dummy" # pretend the filename is understood by a loader m.__loader__ = "dummy" # pretend the filename is understood by a loader
exec("def x(): pass", m.__dict__) exec("def x(): pass", m.__dict__)
......
This diff is collapsed.
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