more Python3 fixes (unicode, basestring)
This commit is contained in:
parent
860d18cae8
commit
fe632fbeab
12 changed files with 25 additions and 1901 deletions
|
@ -1,7 +1,6 @@
|
||||||
# cybertools.commerce.order
|
# cybertools.commerce.order
|
||||||
|
|
||||||
"""
|
""" Order and order item classes.
|
||||||
Order and order item classes.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
@ -46,7 +45,7 @@ class OrderItem(Track):
|
||||||
def getObject(self, ref):
|
def getObject(self, ref):
|
||||||
if isinstance(ref, int):
|
if isinstance(ref, int):
|
||||||
return getObjectForUid(ref)
|
return getObjectForUid(ref)
|
||||||
if isinstance(ref, basestring):
|
if isinstance(ref, str):
|
||||||
if ref.isdigit:
|
if ref.isdigit:
|
||||||
return getObjectForUid(int(ref))
|
return getObjectForUid(int(ref))
|
||||||
if ':' in ref:
|
if ':' in ref:
|
||||||
|
|
|
@ -166,8 +166,7 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
|
||||||
if comparisonValue in (None, '',):
|
if comparisonValue in (None, '',):
|
||||||
return True
|
return True
|
||||||
value = self.field.getSelectValue(row)
|
value = self.field.getSelectValue(row)
|
||||||
if (self.field.fieldType == 'number' and
|
if (self.field.fieldType == 'number' and isinstance(comparisonValue, str)):
|
||||||
isinstance(comparisonValue, basestring)):
|
|
||||||
comparisonValue = int(comparisonValue)
|
comparisonValue = int(comparisonValue)
|
||||||
op = operators.get(self.operator)
|
op = operators.get(self.operator)
|
||||||
if op is None:
|
if op is None:
|
||||||
|
|
|
@ -1,23 +1,6 @@
|
||||||
#
|
# cybertools.composer.report.result
|
||||||
# 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
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
""" Report result sets and related classes.
|
||||||
Report result sets and related classes.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
@ -165,7 +148,7 @@ class ResultSet(object):
|
||||||
subTotalsRow.subTotalsGroupColumns = []
|
subTotalsRow.subTotalsGroupColumns = []
|
||||||
rowId = ''
|
rowId = ''
|
||||||
value = gf.getRawValue(row)
|
value = gf.getRawValue(row)
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, str):
|
||||||
rowId = '%s-%s' % (gf.name, normalizeName(value))
|
rowId = '%s-%s' % (gf.name, normalizeName(value))
|
||||||
rowId = rowId.replace('.', '_')
|
rowId = rowId.replace('.', '_')
|
||||||
if isinstance(value, AdapterBase):
|
if isinstance(value, AdapterBase):
|
||||||
|
@ -268,7 +251,7 @@ class ResultSet(object):
|
||||||
for idx, f in enumerate(self.groupColumns):
|
for idx, f in enumerate(self.groupColumns):
|
||||||
name = f.name
|
name = f.name
|
||||||
value = f.getRawValue(row)
|
value = f.getRawValue(row)
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, str):
|
||||||
value = normalizeName(value)
|
value = normalizeName(value)
|
||||||
value = value.replace('.', '_')
|
value = value.replace('.', '_')
|
||||||
row.subTotalsRowIds = copy(row.subTotalsRowIds) +\
|
row.subTotalsRowIds = copy(row.subTotalsRowIds) +\
|
||||||
|
|
|
@ -1,25 +1,6 @@
|
||||||
#
|
# cybertools.composer.schema.browser.report
|
||||||
# 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
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
""" View classes for CSV export.
|
||||||
View classes for CSV export.
|
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
|
@ -101,13 +82,13 @@ class RegistrationsExportCsv(FormManagerView):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def encode(self, text):
|
def encode(self, text):
|
||||||
if type(text) is unicode:
|
if isinstance(text, str):
|
||||||
result = []
|
result = []
|
||||||
for c in text:
|
for c in text:
|
||||||
try:
|
try:
|
||||||
c = c.encode(self.encoding)
|
c = c.encode(self.encoding)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
c = '?'
|
c = b'?'
|
||||||
result.append(c)
|
result.append(c)
|
||||||
text = ''.join(result)
|
text = b''.join(result)
|
||||||
return text
|
return text
|
||||||
|
|
|
@ -111,7 +111,7 @@ class AutoElement(Element):
|
||||||
try:
|
try:
|
||||||
return super(AutoElement, self).__getitem__(key)
|
return super(AutoElement, self).__getitem__(key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if isinstance(key, basestring):
|
if isinstance(key, str):
|
||||||
result = self.__class__(self.namespace, key, parent=self)
|
result = self.__class__(self.namespace, key, parent=self)
|
||||||
self.children[key] = result
|
self.children[key] = result
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
#
|
# cybertools.pyscript.browser
|
||||||
# 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
|
|
||||||
#
|
|
||||||
|
|
||||||
"""Python Script Browser Views
|
"""Python Script Browser Views
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from zope.app.form.browser.editview import EditView
|
from zope.app.form.browser.editview import EditView
|
||||||
|
@ -33,9 +15,9 @@ class PythonScriptEval(object):
|
||||||
self.request.response.setHeader('content-type',
|
self.request.response.setHeader('content-type',
|
||||||
self.context.contentType)
|
self.context.contentType)
|
||||||
result = self.context(self.request, **kw)
|
result = self.context(self.request, **kw)
|
||||||
if type(result) is unicode:
|
if isinstance(result, str):
|
||||||
return result
|
return result
|
||||||
return unicode(result)
|
return result.decode()
|
||||||
|
|
||||||
|
|
||||||
class PythonScriptEditView(EditView):
|
class PythonScriptEditView(EditView):
|
||||||
|
|
|
@ -35,7 +35,7 @@ unrestricted_objects = ('rpy', 'r', 'as_py', 'rstat')
|
||||||
|
|
||||||
|
|
||||||
def compile(text, filename, mode):
|
def compile(text, filename, mode):
|
||||||
if not isinstance(text, basestring):
|
if not isinstance(text, str):
|
||||||
raise TypeError("Compiled source must be string")
|
raise TypeError("Compiled source must be string")
|
||||||
gen = RExpression(text, str(filename), mode)
|
gen = RExpression(text, str(filename), mode)
|
||||||
gen.compile()
|
gen.compile()
|
||||||
|
@ -115,11 +115,11 @@ class PythonScript(Contained, Persistent):
|
||||||
# compile() don't accept '\r' altogether
|
# compile() don't accept '\r' altogether
|
||||||
source = source.replace("\r\n", "\n")
|
source = source.replace("\r\n", "\n")
|
||||||
source = source.replace("\r", "\n")
|
source = source.replace("\r", "\n")
|
||||||
if isinstance(source, unicode):
|
if isinstance(source, str):
|
||||||
# Use special conversion function to work around
|
# Use special conversion function to work around
|
||||||
# compiler-module failure to handle unicode in literals
|
# compiler-module failure to handle unicode in literals
|
||||||
try:
|
try:
|
||||||
source = source.encode('ascii')
|
source = source.encode()
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
return self._tripleQuotedString.sub(_print_usrc, source)
|
return self._tripleQuotedString.sub(_print_usrc, source)
|
||||||
return self._tripleQuotedString.sub(r"\1print \2\3", source)
|
return self._tripleQuotedString.sub(r"\1print \2\3", source)
|
||||||
|
|
|
@ -29,21 +29,16 @@ class Cell(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
value = self.value
|
return str(self.value) or ''
|
||||||
if value:
|
|
||||||
if isinstance(value, unicode):
|
|
||||||
return value
|
|
||||||
return unicode(str(value))
|
|
||||||
return u''
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def token(self):
|
def token(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def sortKey(self):
|
def sortKey(self):
|
||||||
return self.value
|
return self.text
|
||||||
|
|
||||||
url = urlTitle = u''
|
url = urlTitle = ''
|
||||||
|
|
||||||
|
|
||||||
@implementer(IRow)
|
@implementer(IRow)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class FileSystemStorage(object):
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.warning(e)
|
logger.warning(e)
|
||||||
#'File %r cannot be read.' % fn)
|
#'File %r cannot be read.' % fn)
|
||||||
return ''
|
return b''
|
||||||
|
|
||||||
def getSize(self, address, params={}):
|
def getSize(self, address, params={}):
|
||||||
subDir = params.get('subdirectory')
|
subDir = params.get('subdirectory')
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,3 +0,0 @@
|
||||||
"""
|
|
||||||
$Id$
|
|
||||||
"""
|
|
|
@ -66,7 +66,7 @@ class ExternalEditorView(object):
|
||||||
|
|
||||||
def fromUnicode(text):
|
def fromUnicode(text):
|
||||||
if not text:
|
if not text:
|
||||||
return ''
|
return b''
|
||||||
if isinstance(text, unicode):
|
if isinstance(text, str):
|
||||||
return text.encode('UTF-8')
|
return text.encode('UTF-8')
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Add table
Reference in a new issue