CVS: tmda-cgi Install.py,1.9,1.10 LocalConfig.py,1.5,1.6 Session.py,1.31,1.32 Unicode.py,1.1,1.2

Gre7g Luterman <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda-cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv21790

Modified Files:
	Install.py LocalConfig.py Session.py Unicode.py 
Log Message:
Install now tricks Python into re-loading Defaults on an install.  Python 2.2
did this just fine, but it just didn't work under 2.1.  Go figure.

Removed some other Python 2.2 specific code.


Index: Install.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Install.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Install.py	9 May 2003 05:04:59 -0000	1.9
+++ Install.py	14 May 2003 05:58:05 -0000	1.10
@@ -286,15 +286,26 @@
     except OSError:
       pass
 
+  # At this point, we need to reload Defaults.  This is easy to do under
+  # Python 2.2, but for some reason Python 2.1 will return an ImportError.
+  # To circumvent this problem, we use execfile and let Defaults be a
+  # dictionary instead of a module to access the contents.  Ugly, but
+  # effective.
+
   # Try to import Defaults again.
   try:
-    from TMDA import Defaults
+    CWD = os.getcwd()
+    os.chdir(os.path.join(os.environ["TMDA_BASE_DIR"], "TMDA"))
+    Defaults = {}
+    execfile("Defaults.py", Defaults)
+    os.chdir(CWD)
   except Errors.ConfigError:
+    os.chdir(CWD)
     Revert(FilesToInstall, Backup, "Re-importing Defaults<br>%s" % ErrStr)
 
   # Prepare template
   T = Template.Template("installed.html")
-  T["EMail"] = "%s@%s" % (Defaults.USERNAME, Defaults.HOSTNAME)
+  T["EMail"] = "%s@%s" % (Defaults["USERNAME"], Defaults["HOSTNAME"])
   Row = T["Row"]
   if len(FilesClobbered):
     # List files clobbered

Index: LocalConfig.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/LocalConfig.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalConfig.py	4 May 2003 19:52:46 -0000	1.5
+++ LocalConfig.py	14 May 2003 05:58:05 -0000	1.6
@@ -66,7 +66,7 @@
 
   global LineNum, AssignVar
 
-  if type(ASP) in StringTypes:
+  if type(ASP) in [StringType, UnicodeType]:
     return ASP
   elif type(ASP[0]) == IntType:
     RetVal = Parse(ASP[1], AllowSym)

Index: Session.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Session.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Session.py	8 May 2003 00:17:43 -0000	1.31
+++ Session.py	14 May 2003 05:58:05 -0000	1.32
@@ -296,7 +296,7 @@
       try:
         self.__suid__("web")
         Filename = os.environ["TMDA_SESSION_PREFIX"] + self.SID
-        if os.stat(Filename).st_uid != os.geteuid():
+        if os.stat(Filename)[4] != os.geteuid():
           CgiUtil.TermError("CGI_USER does not own session file.",
             "Something suspicious is going on here.  This should not happen.",
             "open file",
@@ -468,7 +468,7 @@
           pass
 
   def __delitem__(self, a):
-    if type(a) in StringTypes:
+    if type(a) in [StringType, UnicodeType]:
       del self.PVars[a]
     else:
       ID = ":".join(a)
@@ -478,7 +478,7 @@
         self.ThemeVars.remove_option(a[0], a[1])
 
   def __getitem__(self, a):
-    if type(a) in StringTypes:
+    if type(a) in [StringType, UnicodeType]:
       return self.PVars[a]
     else:
       ID = ":".join(a)
@@ -488,13 +488,13 @@
         return self.ThemeVars.get(a[0], a[1], 1)
 
   def __setitem__(self, a, b):
-    if type(a) in StringTypes:
+    if type(a) in [StringType, UnicodeType]:
       self.PVars[a] = b
     else:
       self.PVars[":".join(a)] = b
 
   def has_key(self, a):
-    if type(a) in StringTypes:
+    if type(a) in [StringType, UnicodeType]:
       return self.PVars.has_key(a)
     else:
       return self.PVars.has_key(":".join(a)) or \

Index: Unicode.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Unicode.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Unicode.py	13 May 2003 21:29:08 -0000	1.1
+++ Unicode.py	14 May 2003 05:58:05 -0000	1.2
@@ -1,115 +1,115 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2002 Gre7g Luterman <[email protected]>
-#
-# This file is part of TMDA.
-#
-# TMDA is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.  A copy of this license should
-# be included in the file COPYING.
-#
-# TMDA is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with TMDA; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-"Unicode utilities for tmda-cgi."
-
-import codecs
-import re
-
-import Template
-
-# Handy values
-AltChar  = re.compile("[\x80-\xFF]")
-UTF8     = codecs.getencoder("utf-8")
-
-def Xlate(Chr):
-  if ord(Chr) >= 160: return unichr(ord(Chr))
-  if Chr == "€": return u"\u20AC"
-  if Chr == "‚": return u"\u201A"
-  if Chr == "ƒ": return u"\u2061"
-  if Chr == "„": return u"\u201E"
-  if Chr == "…": return u"\u2026"
-  if Chr == "†": return u"\u2020"
-  if Chr == "‡": return u"\u2021"
-  if Chr == "‰": return u"\u2030"
-  if Chr == "‹": return u"\u2039"
-  if Chr == "‘": return u"\u2018"
-  if Chr == "’": return u"\u2019"
-  if Chr == "“": return u"\u201C"
-  if Chr == "”": return u"\u201D"
-  if Chr == "•": return u"\u2022"
-  if Chr == "–": return u"\u2014"
-  if Chr == "—": return u"\u2015"
-  if Chr == "™": return u"\u2122"
-  return u"\u007F"
-
-def Iso8859(Str):
-  RetVal = u""
-  while 1:
-    Match = AltChar.search(Str)
-    if Match:
-      RetVal += Str[:Match.start()] + Xlate(Match.group(0))
-      Str = Str[Match.end():]
-    else:
-      break
-  RetVal += Str
-  return (RetVal,)
-
-def TranslateToUTF8(CharSet, Str, Errors):
-  "Represent a string in UTF-8."
-  import email.Charset
-
-  if not CharSet:
-    return Str
-  CS = email.Charset.Charset(CharSet)
-  CharSet = CS.input_charset
-
-  # Find appropriate decoder
-  if CharSet == "iso-8859-1":
-    Decoder = Iso8859
-  else:
-    try:
-      Decoder = codecs.getdecoder(CharSet)
-    except LookupError:
-      try:
-        # Is it GB2312?
-        if CharSet == "gb2312":
-          import chinese.gb2312
-          Lib = chinese.gb2312
-        # Is it GBK?
-        elif CharSet == "gbk":
-          import chinese.gbk
-          Lib = chinese.gbk
-        # Is it Big5?
-        elif CharSet == "big5":
-          import chinese.big5
-          Lib = chinese.big5
-        # Don't recognize it.  Was it our fallback?
-        elif CharSet == PVars[("General", "CSEncoding")]:
-          # It was our fallback!  Give up now!
-          return Str
-        # Mark it and use the fallback
-        else:
-          return "(%s) %s" % (CharSet,
-            TranslateToUTF8(PVars[("General", "CSEncoding")], Str, Errors))
-        Decoder = Lib.Codec().decode
-      except ImportError:
-        # We know what it was, but we don't have the library installed.
-        return "(%s) %s" % (CharSet, Str)
-
-  # Decode string to Unicode
-  try:
-    Uni = Decoder(Str, errors = Errors)[0]
-  except TypeError:
-    Uni = Decoder(Str)[0]
-
-  # Encode for UTF-8
-  return UTF8(Uni)[0]
+#!/usr/bin/env python
+#
+# Copyright (C) 2002 Gre7g Luterman <[email protected]>
+#
+# This file is part of TMDA.
+#
+# TMDA is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.  A copy of this license should
+# be included in the file COPYING.
+#
+# TMDA is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with TMDA; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"Unicode utilities for tmda-cgi."
+
+import codecs
+import re
+
+import Template
+
+# Handy values
+AltChar  = re.compile("[\x80-\xFF]")
+UTF8     = codecs.lookup("utf-8")[0]
+
+def Xlate(Chr):
+  if ord(Chr) >= 160: return unichr(ord(Chr))
+  if Chr == "€": return u"\u20AC"
+  if Chr == "‚": return u"\u201A"
+  if Chr == "ƒ": return u"\u2061"
+  if Chr == "„": return u"\u201E"
+  if Chr == "…": return u"\u2026"
+  if Chr == "†": return u"\u2020"
+  if Chr == "‡": return u"\u2021"
+  if Chr == "‰": return u"\u2030"
+  if Chr == "‹": return u"\u2039"
+  if Chr == "‘": return u"\u2018"
+  if Chr == "’": return u"\u2019"
+  if Chr == "“": return u"\u201C"
+  if Chr == "”": return u"\u201D"
+  if Chr == "•": return u"\u2022"
+  if Chr == "–": return u"\u2014"
+  if Chr == "—": return u"\u2015"
+  if Chr == "™": return u"\u2122"
+  return u"\u007F"
+
+def Iso8859(Str):
+  RetVal = u""
+  while 1:
+    Match = AltChar.search(Str)
+    if Match:
+      RetVal += Str[:Match.start()] + Xlate(Match.group(0))
+      Str = Str[Match.end():]
+    else:
+      break
+  RetVal += Str
+  return (RetVal,)
+
+def TranslateToUTF8(CharSet, Str, Errors):
+  "Represent a string in UTF-8."
+  import email.Charset
+
+  if not CharSet:
+    return Str
+  CS = email.Charset.Charset(CharSet)
+  CharSet = CS.input_charset
+
+  # Find appropriate decoder
+  if CharSet == "iso-8859-1":
+    Decoder = Iso8859
+  else:
+    try:
+      Decoder = codecs.getdecoder(CharSet)
+    except LookupError:
+      try:
+        # Is it GB2312?
+        if CharSet == "gb2312":
+          import chinese.gb2312
+          Lib = chinese.gb2312
+        # Is it GBK?
+        elif CharSet == "gbk":
+          import chinese.gbk
+          Lib = chinese.gbk
+        # Is it Big5?
+        elif CharSet == "big5":
+          import chinese.big5
+          Lib = chinese.big5
+        # Don't recognize it.  Was it our fallback?
+        elif CharSet == PVars[("General", "CSEncoding")]:
+          # It was our fallback!  Give up now!
+          return Str
+        # Mark it and use the fallback
+        else:
+          return "(%s) %s" % (CharSet,
+            TranslateToUTF8(PVars[("General", "CSEncoding")], Str, Errors))
+        Decoder = Lib.Codec().decode
+      except ImportError:
+        # We know what it was, but we don't have the library installed.
+        return "(%s) %s" % (CharSet, Str)
+
+  # Decode string to Unicode
+  try:
+    Uni = Decoder(Str, errors = Errors)[0]
+  except TypeError:
+    Uni = Decoder(Str)[0]
+
+  # Encode for UTF-8
+  return UTF8(Uni)[0]

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.