diff options
author | R. Tyler Ballance <tyler@monkeypox.org> | 2009-12-27 16:51:49 -0800 |
---|---|---|
committer | R. Tyler Ballance <tyler@monkeypox.org> | 2009-12-27 16:55:57 -0800 |
commit | 0900226c99b77d633410b1aaeb6cdc4ca9b625a2 (patch) | |
tree | 12a5490d4dd223c4dfd169caf4a0e7290aefa6e4 | |
parent | 1ee4ba40d6ab9a92f941ff5ccab30066b921bcb2 (diff) | |
download | python-cheetah-0900226c99b77d633410b1aaeb6cdc4ca9b625a2.tar.gz |
Remove references to the `new` module
-rwxr-xr-x | cheetah/ImportHooks.py | 23 | ||||
-rw-r--r-- | cheetah/Parser.py | 10 | ||||
-rw-r--r-- | cheetah/SettingsManager.py | 8 | ||||
-rw-r--r-- | cheetah/Template.py | 27 | ||||
-rw-r--r-- | cheetah/Tests/SyntaxAndOutput.py | 1 |
5 files changed, 23 insertions, 46 deletions
diff --git a/cheetah/ImportHooks.py b/cheetah/ImportHooks.py index a29dfed..0ae5141 100755 --- a/cheetah/ImportHooks.py +++ b/cheetah/ImportHooks.py @@ -1,33 +1,24 @@ -# $Id: ImportHooks.py,v 1.27 2007/11/16 18:28:47 tavis_rudd Exp $ +#!/usr/bin/env python -"""Provides some import hooks to allow Cheetah's .tmpl files to be imported +""" +Provides some import hooks to allow Cheetah's .tmpl files to be imported directly like Python .py modules. To use these: import Cheetah.ImportHooks Cheetah.ImportHooks.install() - -Meta-Data -================================================================================ -Author: Tavis Rudd <tavis@damnsimple.com> -License: This software is released for unlimited distribution under the - terms of the MIT license. See the LICENSE file. -Version: $Revision: 1.27 $ -Start Date: 2001/03/30 -Last Revision Date: $Date: 2007/11/16 18:28:47 $ -""" -__author__ = "Tavis Rudd <tavis@damnsimple.com>" -__revision__ = "$Revision: 1.27 $"[11:-2] +""" import sys import os.path import types import __builtin__ -import new import imp from threading import RLock import string import traceback +import types + from Cheetah import ImportManager from Cheetah.ImportManager import DirOwner from Cheetah.Compiler import Compiler @@ -95,7 +86,7 @@ class CheetahDirOwner(DirOwner): __file__ = tmplPath co = compile(code+'\n', __file__, 'exec') - mod = imp.new_module(name) + mod = types.ModuleType(name) mod.__file__ = co.co_filename if _cacheDir: mod.__orig_file__ = tmplPath # @@TR: this is used in the WebKit diff --git a/cheetah/Parser.py b/cheetah/Parser.py index 8810ac8..98bceda 100644 --- a/cheetah/Parser.py +++ b/cheetah/Parser.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python """ Parser classes for Cheetah's Compiler @@ -12,11 +13,10 @@ import os import sys import re from re import DOTALL, MULTILINE -from types import StringType, ListType, TupleType, ClassType, TypeType +import types import time from tokenize import pseudoprog import inspect -import new import traceback from Cheetah.SourceReader import SourceReader @@ -1365,7 +1365,7 @@ class _HighLevelParser(_LowLevelParser): def normalizeParserVal(val): if isinstance(val, (str, unicode)): handler = getattr(self, val) - elif type(val) in (ClassType, TypeType): + elif isinstance(val, type): handler = val(self) elif hasattr(val, '__call__'): handler = val @@ -1416,7 +1416,7 @@ class _HighLevelParser(_LowLevelParser): for macroName, callback in macroDirectives.items(): - if type(callback) in (ClassType, TypeType): + if isinstance(callback, type): callback = callback(parser=self) assert callback self._macros[macroName] = callback @@ -2351,7 +2351,7 @@ class _HighLevelParser(_LowLevelParser): assert 'src' not in kwArgs kwArgs['src'] = srcBlock - if isinstance(macro, new.instancemethod): + if isinstance(macro, types.MethodType): co = macro.im_func.func_code elif (hasattr(macro, '__call__') and hasattr(macro.__call__, 'im_func')): diff --git a/cheetah/SettingsManager.py b/cheetah/SettingsManager.py index 94f7723..437954b 100644 --- a/cheetah/SettingsManager.py +++ b/cheetah/SettingsManager.py @@ -4,9 +4,7 @@ import copy as copyModule from ConfigParser import ConfigParser import re from tokenize import Intnumber, Floatnumber, Number -from types import * import types -import new import time from StringIO import StringIO # not cStringIO because of unicode support import imp # used by SettingsManager.updateSettingsFromPySrcFile() @@ -15,10 +13,6 @@ import imp # used by SettingsManager.updateSettingsFromPySrcFile numberRE = re.compile(Number) complexNumberRE = re.compile('[\(]*' +Number + r'[ \t]*\+[ \t]*' + Number + '[\)]*') -convertableToStrTypes = (StringType, IntType, FloatType, - LongType, ComplexType, NoneType, - UnicodeType) - ################################################## ## FUNCTIONS ## @@ -110,7 +104,7 @@ class _SettingsCollector(object): newSettings = {'self':self} exec((theString+os.linesep), globalsDict, newSettings) del newSettings['self'] - module = new.module('temp_settings_module') + module = types.ModuleType('temp_settings_module') module.__dict__.update(newSettings) return self.readSettingsFromModule(module) diff --git a/cheetah/Template.py b/cheetah/Template.py index c76f305..f4cb4f8 100644 --- a/cheetah/Template.py +++ b/cheetah/Template.py @@ -8,7 +8,6 @@ See the docstring in the Template class and the Users' Guide for more informatio ## DEPENDENCIES import sys # used in the error handling code import re # used to define the internal delims regex -import new # used to bind methods and create dummy modules import logging import string import os.path @@ -21,11 +20,6 @@ import traceback import pprint import cgi # Used by .webInput() if the template is a CGI script. import types -from types import StringType, ClassType -try: - from types import StringTypes -except ImportError: - StringTypes = (types.StringType, types.UnicodeType) try: from threading import Lock @@ -595,7 +589,7 @@ class Template(Servlet): if isinstance(baseclass, Template): baseclass = baseclass.__class__ - if not isinstance(baseclass, (types.NoneType, basestring, types.ClassType, types.TypeType)): + if not isinstance(baseclass, (types.NoneType, basestring, type)): raise TypeError(errmsg % ('baseclass', 'string, class or None')) if cacheCompilationResults is Unspecified: @@ -679,7 +673,7 @@ class Template(Servlet): if baseclass: if isinstance(baseclass, basestring): baseclassName = baseclass - elif isinstance(baseclass, (types.ClassType, types.TypeType)): + elif isinstance(baseclass, type): # @@TR: should soft-code this baseclassName = 'CHEETAH_dynamicallyAssignedBaseClass_'+baseclass.__name__ baseclassValue = baseclass @@ -768,7 +762,7 @@ class Template(Servlet): open(__file__, 'w').write(generatedModuleCode) # @@TR: should probably restrict the perms, etc. - mod = new.module(str(uniqueModuleName)) + mod = types.ModuleType(str(uniqueModuleName)) if moduleGlobals: for k, v in moduleGlobals.items(): setattr(mod, k, v) @@ -978,8 +972,7 @@ class Template(Servlet): for methodname in klass._CHEETAH_requiredCheetahMethods: if not hasattr(concreteTemplateClass, methodname): method = getattr(Template, methodname) - newMethod = new.instancemethod(method.im_func, None, concreteTemplateClass) - #print methodname, method + newMethod = types.MethodType(method.im_func, None, concreteTemplateClass) setattr(concreteTemplateClass, methodname, newMethod) for classMethName in klass._CHEETAH_requiredCheetahClassMethods: @@ -1035,8 +1028,8 @@ class Template(Servlet): else: return super(self.__class__, self).__unicode__() - __str__ = new.instancemethod(__str__, None, concreteTemplateClass) - __unicode__ = new.instancemethod(__unicode__, None, concreteTemplateClass) + __str__ = types.MethodType(__str__, None, concreteTemplateClass) + __unicode__ = types.MethodType(__unicode__, None, concreteTemplateClass) setattr(concreteTemplateClass, '__str__', __str__) setattr(concreteTemplateClass, '__unicode__', __unicode__) @@ -1174,7 +1167,7 @@ class Template(Servlet): ('file', 'string, file open for reading, or None')) if not isinstance(filter, (basestring, types.TypeType)) and not \ - (isinstance(filter, types.ClassType) and issubclass(filter, Filters.Filter)): + (isinstance(filter, type) and issubclass(filter, Filters.Filter)): raise TypeError(errmsgextra % ('filter', 'string or class', '(if class, must be subclass of Cheetah.Filters.Filter)')) @@ -1187,7 +1180,7 @@ class Template(Servlet): err = True if isinstance(errorCatcher, (basestring, types.TypeType)): err = False - if isinstance(errorCatcher, types.ClassType) and \ + if isinstance(errorCatcher, type) and \ issubclass(errorCatcher, ErrorCatchers.ErrorCatcher): err = False if err: @@ -1505,7 +1498,7 @@ class Template(Servlet): if errorCatcher: if isinstance(errorCatcher, basestring): errorCatcherClass = getattr(ErrorCatchers, errorCatcher) - elif isinstance(errorCatcher, ClassType): + elif isinstance(errorCatcher, type): errorCatcherClass = errorCatcher self._CHEETAH__errorCatcher = ec = errorCatcherClass(self) @@ -1578,7 +1571,7 @@ class Template(Servlet): if not raw: if includeFrom == 'file': source = None - if type(srcArg) in StringTypes: + if isinstance(srcArg, basestring): if hasattr(self, 'serverSidePath'): file = path = self.serverSidePath(srcArg) else: diff --git a/cheetah/Tests/SyntaxAndOutput.py b/cheetah/Tests/SyntaxAndOutput.py index 92c129b..4fc467c 100644 --- a/cheetah/Tests/SyntaxAndOutput.py +++ b/cheetah/Tests/SyntaxAndOutput.py @@ -22,7 +22,6 @@ import re from copy import deepcopy import os import os.path -import new import warnings import unittest |