changeset 1181:a7f8dceb4410

remove types module usage
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 14 Aug 2006 00:12:34 +0200
parents c1c0d7f6f2b4
children 5de0dc972701
files MoinMoin/action/SpellCheck.py MoinMoin/formatter/__init__.py MoinMoin/parser/text_rst.py MoinMoin/util/web.py MoinMoin/wikiutil.py MoinMoin/wikixml/marshal.py
diffstat 6 files changed, 16 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SpellCheck.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/action/SpellCheck.py	Mon Aug 14 00:12:34 2006 +0200
@@ -99,7 +99,6 @@
 
 
 def _addLocalWords(request):
-    import types
     from MoinMoin.PageEditor import PageEditor
 
     # get the new words as a string (if any are marked at all)
--- a/MoinMoin/formatter/__init__.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/formatter/__init__.py	Mon Aug 14 00:12:34 2006 +0200
@@ -7,12 +7,13 @@
     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
     @license: GNU GPL, see COPYING for details.
 """
+import re
+
 from MoinMoin.util import pysupport
+from MoinMoin import wikiutil
 
 modules = pysupport.getPackageModules(__file__)
 
-from MoinMoin import wikiutil
-import re, types
 
 class FormatterBase:
     """ This defines the output interface used all over the rest of the code.
@@ -37,7 +38,7 @@
         self._base_depth = 0
 
     def set_highlight_re(self, hi_re=None):
-        if type(hi_re) in [types.StringType, types.UnicodeType]:
+        if isinstance(hi_re, (str, unicode)):
             try:
                 self._highlight_re = re.compile(hi_re, re.U + re.IGNORECASE)
             except re.error:
--- a/MoinMoin/parser/text_rst.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/parser/text_rst.py	Mon Aug 14 00:12:34 2006 +0200
@@ -15,7 +15,6 @@
 import __builtin__
 import sys
 
-import types
 import os
 
 # docutils imports are below
@@ -227,7 +226,7 @@
     def append(self, text):
         f = sys._getframe()
         if f.f_back.f_code.co_filename.endswith('html4css1.py'):
-            if isinstance(text, types.StringType) or isinstance(text, types.UnicodeType):
+            if isinstance(text, (str, unicode)):
                 text = self.formatter.rawHTML(text)
         list.append(self, text)
 
@@ -256,7 +255,7 @@
         # Make all internal lists RawHTMLLists, see RawHTMLList class
         # comment for more information.
         for i in self.__dict__:
-            if isinstance(getattr(self, i), types.ListType):
+            if isinstance(getattr(self, i), list):
                 setattr(self, i, RawHTMLList(formatter))
 
     def depart_docinfo(self, node):
--- a/MoinMoin/util/web.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/util/web.py	Mon Aug 14 00:12:34 2006 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import re, types
+import re
 from MoinMoin import config
 
 def getIntegerInput(request, fieldname, default=None, minval=None, maxval=None):
@@ -224,11 +224,11 @@
             another Color instance, a tuple containing 3 color values, 
             a Netscape color name or a HTML color ("#RRGGBB").
         """
-        if isinstance(color, types.TupleType) and len(color) == 3:
+        if isinstance(color, tuple) and len(color) == 3:
             self.r, self.g, self.b = map(int, color)
         elif isinstance(color, Color):
             self.r, self.g, self.b = color.r, color.g, color.b
-        elif not isinstance(color, types.StringType):
+        elif not isinstance(color, str):
             raise TypeError("Color() expects a Color instance, a RGB triple or a color string")
         elif color[0] == '#':
             color = long(color[1:], 16)
--- a/MoinMoin/wikiutil.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/wikiutil.py	Mon Aug 14 00:12:34 2006 +0200
@@ -11,7 +11,6 @@
 import os
 import re
 import time
-import types
 import urllib
 
 from MoinMoin import util, version, config
@@ -1131,7 +1130,7 @@
                 continue
             if hasattr(Parser, 'extensions'):
                 exts = Parser.extensions
-                if type(exts) == types.ListType:
+                if isinstance(exts, list):
                     for ext in Parser.extensions:
                         etp[ext] = Parser
                 elif str(exts) == '*':
@@ -1531,14 +1530,14 @@
 
 def createTicket(tm=None):
     """Create a ticket using a site-specific secret (the config)"""
-    import sha, time, types
+    import sha
     ticket = tm or "%010x" % time.time()
     digest = sha.new()
     digest.update(ticket)
 
     cfgvars = vars(config)
     for var in cfgvars.values():
-        if type(var) is types.StringType:
+        if isinstance(var, str):
             digest.update(repr(var))
 
     return "%s.%s" % (ticket, digest.hexdigest())
--- a/MoinMoin/wikixml/marshal.py	Sun Aug 13 23:43:20 2006 +0200
+++ b/MoinMoin/wikixml/marshal.py	Mon Aug 14 00:12:34 2006 +0200
@@ -6,9 +6,6 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import types
-
-
 class Marshal:
     """ Serialize Python data structures to XML.
 
@@ -64,16 +61,16 @@
         if data is None:
             content = "<none/>"
 
-        elif isinstance(data, types.StringType):
+        elif isinstance(data, str):
             content = (data.replace("&", "&amp;") # Must be done first!
                            .replace("<", "&lt;")
                            .replace(">", "&gt;"))
 
-        elif isinstance(data, types.DictionaryType):
+        elif isinstance(data, dict):
             for key, value in data.items():
                 add_content(self.__toXML(key, value))
 
-        elif isinstance(data, types.ListType) or isinstance(data, types.TupleType):
+        elif isinstance(data, (list, tuple)):
             for item in data:
                 add_content(self.__toXML(self.ITEM_CONTAINER, item))
 
@@ -89,7 +86,7 @@
                                 .replace(">", "&gt;"))
 
         # Close container element
-        if isinstance(content, types.StringType):
+        if isinstance(content, str):
             # No Whitespace
             if element:
                 content = ['<%s>%s</%s>' % (element, content, element)]