Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove references to the `new` module

  • Loading branch information...
commit 0900226c99b77d633410b1aaeb6cdc4ca9b625a2 1 parent 1ee4ba4
R. Tyler Croy rtyler authored
23 cheetah/ImportHooks.py
View
@@ -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 @@ def _compile(self, name, tmplPath):
__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
10 cheetah/Parser.py
View
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
"""
Parser classes for Cheetah's Compiler
@@ -12,11 +13,10 @@
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 @@ def _initDirectives(self):
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 @@ def normalizeParserVal(val):
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 @@ def getArgs(*pargs, **kws):
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')):
8 cheetah/SettingsManager.py
View
@@ -4,9 +4,7 @@
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 @@
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 @@ def readSettingsFromPySrcStr(self, theString):
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)
27 cheetah/Template.py
View
@@ -8,7 +8,6 @@
## 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 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 @@ def __str__(self): return self.respond()
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 @@ def __str__(self): return self.respond()
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 @@ def __str__(self): return self.respond()
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 @@ def _addCheetahPlumbingCodeToClass(klass, concreteTemplateClass):
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 @@ def __unicode__(self):
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 @@ def __init__(self, source=None,
('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 @@ def __init__(self, source=None,
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 @@ def _initCheetahInstance(self,
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 @@ def _handleCheetahInclude(self, srcArg, trans=None, includeFrom='file', raw=Fals
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:
1  cheetah/Tests/SyntaxAndOutput.py
View
@@ -22,7 +22,6 @@
from copy import deepcopy
import os
import os.path
-import new
import warnings
import unittest
Please sign in to comment.
Something went wrong with that request. Please try again.