more Python3 fixes (unicode, basestring)

This commit is contained in:
Helmut Merz 2025-01-11 11:35:21 +01:00
parent 860d18cae8
commit fe632fbeab
12 changed files with 25 additions and 1901 deletions

View file

@ -1,7 +1,6 @@
# cybertools.commerce.order
"""
Order and order item classes.
""" Order and order item classes.
"""
from zope.cachedescriptors.property import Lazy
@ -46,7 +45,7 @@ class OrderItem(Track):
def getObject(self, ref):
if isinstance(ref, int):
return getObjectForUid(ref)
if isinstance(ref, basestring):
if isinstance(ref, str):
if ref.isdigit:
return getObjectForUid(int(ref))
if ':' in ref:

View file

@ -166,8 +166,7 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
if comparisonValue in (None, '',):
return True
value = self.field.getSelectValue(row)
if (self.field.fieldType == 'number' and
isinstance(comparisonValue, basestring)):
if (self.field.fieldType == 'number' and isinstance(comparisonValue, str)):
comparisonValue = int(comparisonValue)
op = operators.get(self.operator)
if op is None:

View file

@ -1,23 +1,6 @@
#
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# cybertools.composer.report.result
"""
Report result sets and related classes.
""" Report result sets and related classes.
"""
from copy import copy
@ -165,7 +148,7 @@ class ResultSet(object):
subTotalsRow.subTotalsGroupColumns = []
rowId = ''
value = gf.getRawValue(row)
if isinstance(value, basestring):
if isinstance(value, str):
rowId = '%s-%s' % (gf.name, normalizeName(value))
rowId = rowId.replace('.', '_')
if isinstance(value, AdapterBase):
@ -268,7 +251,7 @@ class ResultSet(object):
for idx, f in enumerate(self.groupColumns):
name = f.name
value = f.getRawValue(row)
if isinstance(value, basestring):
if isinstance(value, str):
value = normalizeName(value)
value = value.replace('.', '_')
row.subTotalsRowIds = copy(row.subTotalsRowIds) +\

View file

@ -1,25 +1,6 @@
#
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# cybertools.composer.schema.browser.report
"""
View classes for CSV export.
$Id$
""" View classes for CSV export.
"""
import csv
@ -101,13 +82,13 @@ class RegistrationsExportCsv(FormManagerView):
return result
def encode(self, text):
if type(text) is unicode:
if isinstance(text, str):
result = []
for c in text:
try:
c = c.encode(self.encoding)
except UnicodeEncodeError:
c = '?'
c = b'?'
result.append(c)
text = ''.join(result)
text = b''.join(result)
return text

View file

@ -111,7 +111,7 @@ class AutoElement(Element):
try:
return super(AutoElement, self).__getitem__(key)
except KeyError:
if isinstance(key, basestring):
if isinstance(key, str):
result = self.__class__(self.namespace, key, parent=self)
self.children[key] = result
return result

View file

@ -1,24 +1,6 @@
#
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# cybertools.pyscript.browser
"""Python Script Browser Views
$Id$
"""
from zope.app.form.browser.editview import EditView
@ -33,9 +15,9 @@ class PythonScriptEval(object):
self.request.response.setHeader('content-type',
self.context.contentType)
result = self.context(self.request, **kw)
if type(result) is unicode:
if isinstance(result, str):
return result
return unicode(result)
return result.decode()
class PythonScriptEditView(EditView):

View file

@ -35,7 +35,7 @@ unrestricted_objects = ('rpy', 'r', 'as_py', 'rstat')
def compile(text, filename, mode):
if not isinstance(text, basestring):
if not isinstance(text, str):
raise TypeError("Compiled source must be string")
gen = RExpression(text, str(filename), mode)
gen.compile()
@ -115,11 +115,11 @@ class PythonScript(Contained, Persistent):
# compile() don't accept '\r' altogether
source = source.replace("\r\n", "\n")
source = source.replace("\r", "\n")
if isinstance(source, unicode):
if isinstance(source, str):
# Use special conversion function to work around
# compiler-module failure to handle unicode in literals
try:
source = source.encode('ascii')
source = source.encode()
except UnicodeEncodeError:
return self._tripleQuotedString.sub(_print_usrc, source)
return self._tripleQuotedString.sub(r"\1print \2\3", source)

View file

@ -29,21 +29,16 @@ class Cell(object):
@property
def text(self):
value = self.value
if value:
if isinstance(value, unicode):
return value
return unicode(str(value))
return u''
return str(self.value) or ''
@property
def token(self):
return self.value
def sortKey(self):
return self.value
return self.text
url = urlTitle = u''
url = urlTitle = ''
@implementer(IRow)

View file

@ -63,7 +63,7 @@ class FileSystemStorage(object):
except IOError as e:
logger.warning(e)
#'File %r cannot be read.' % fn)
return ''
return b''
def getSize(self, address, params={}):
subDir = params.get('subdirectory')

File diff suppressed because it is too large Load diff

View file

@ -1,3 +0,0 @@
"""
$Id$
"""

View file

@ -66,7 +66,7 @@ class ExternalEditorView(object):
def fromUnicode(text):
if not text:
return ''
if isinstance(text, unicode):
return b''
if isinstance(text, str):
return text.encode('UTF-8')
return text