[Zope] NameError: global name 'string' is not defined SOLUTION
eric.n.dunn@bankofamerica.com
eric.n.dunn@bankofamerica.com
Fri, 07 Jun 2002 11:14:07 -0400
Zope 2.5 on Debian w/ PostgreSQL 7.1 on i686-pc-linux-gnu, compiled by GCC
2.95.4
Found the fix thanks to Jim Penny (and a google search)
Input to my Postgres DB just fine!
http://mail.python.org/pipermail/zope/2001-August/098412.html
# added "import string' line to /lib/python/Products/ZPoPyDA/PoPy_DA.py
import string
database_type='PoPy'
"""%s Database Connection""" % database_type
from PoPy_db import DB
from Shared.DC.ZRDB.Connection import *
from PoPy_browser import *
addPoPyConnectionForm=DTMLFile(
'dtml/PoPyconnectionAdd',
globals(),
default_id='%s_database_connection' % database_type,
default_title='Z %s Database Connection' % database_type,
database_type=database_type,
)
def addPoPyConnection(self, id, title, connection_string,
connected=None,attempts=10,seconds=5,REQUEST=None):
"""Add a Z PoPy DB connection to a folder"""
if not connected is None:
connected = 1
self._setObject(id, PoPyConnection(id,
title,
connection_string,
connected,
attempts,
seconds))
if REQUEST is not None:
return self.manage_main(self,REQUEST)
class PoPyConnection(Connection):
"""A database connection object"""
database_type=database_type
id='%s_database_connection' % database_type
meta_type=title='Z %s Database Connection' % database_type
icon='misc_/Z%sDA/conn' % database_type
_isAnSQLConnection=1
def __init__(self, id, title, connection_string, connected=None,
attempts=10,seconds=5):
Connection.__init__(self,id,title,connection_string,connected)
self.attempts = attempts
self.seconds = seconds
if self._v_connected:
self._v_database_connection.setAttempts(attempts,seconds)
def manage_attempts (self, attempts,seconds,REQUEST):
" "
self.attempts = attempts
self.seconds = seconds
self._v_database_connection.setAttempts(attempts,seconds)
return self.manage_main(self,REQUEST)
manage_main=DTMLFile('dtml/PoPyconnectionStatus', globals())
manage_properties=DTMLFile('dtml/PoPyconnectionEdit', globals())
def manage_edit(self, title, connection_string, connected=None,
attempts=10,seconds=5,REQUEST=None):
"""Change connection"""
self.attempts = attempts
self.seconds = seconds
if self._v_connected:
self._v_database_connection.setAttempts(attempts,seconds)
Connection.manage_edit(self,title,connection_string,connected)
manage_testForm = DTMLFile('dtml/PoPyconnectionTestForm', globals())
def factory(self): return DB
def sql_quote__(self, v, escapes={
'\\': '\\\\',
'\"': '\\\"',
'\'': '\\\'',
'\0': '\\0',
'\n': '\\n',
'\t': '\\t',
'\r': '\\r',
'\b': '\\n',
}):
find=string.find
for c in "\\\"\'\0\n\t\r\b":
if find(v,c) > -1:
v=string.join(string.split(v,c),escapes[c])
return "'%s'" % v