make Python3.12 happy
This commit is contained in:
parent
814d7c0762
commit
aef9ad8cb5
5 changed files with 29 additions and 21 deletions
|
@ -85,8 +85,10 @@ class Executor(object):
|
||||||
error = ''
|
error = ''
|
||||||
try:
|
try:
|
||||||
exec(text, self.namespace)
|
exec(text, self.namespace)
|
||||||
except:
|
except Exception as e:
|
||||||
error = traceback.format_exc()
|
#error = traceback.format_exc()
|
||||||
|
if e:
|
||||||
|
error = traceback.format_exception(e, e, e.__traceback__)
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,8 +112,10 @@ class Evaluator(Executor):
|
||||||
error = ''
|
error = ''
|
||||||
try:
|
try:
|
||||||
result = eval(text, self.namespace)
|
result = eval(text, self.namespace)
|
||||||
except:
|
except Exception as e:
|
||||||
error = traceback.format_exc()
|
#error = traceback.format_exc()
|
||||||
|
if e:
|
||||||
|
error = traceback.format_exception(e, e, e.__traceback__)
|
||||||
return result, error
|
return result, error
|
||||||
|
|
||||||
def evalutateOrExecute(self, text):
|
def evalutateOrExecute(self, text):
|
||||||
|
|
|
@ -107,7 +107,7 @@ value and an - hopefully empty - error string.
|
||||||
(625, '')
|
(625, '')
|
||||||
|
|
||||||
>>> ev.evaluate('30/0')
|
>>> ev.evaluate('30/0')
|
||||||
(None, 'Traceback...ZeroDivisionError...')
|
(None, ['Traceback...ZeroDivisionError...'])
|
||||||
|
|
||||||
Trying to execute a statement leads to a syntax error.
|
Trying to execute a statement leads to a syntax error.
|
||||||
... in Python3 print is a function ...
|
... in Python3 print is a function ...
|
||||||
|
@ -133,4 +133,4 @@ Execution of Statements
|
||||||
''
|
''
|
||||||
|
|
||||||
>>> ex.execute('30/0')
|
>>> ex.execute('30/0')
|
||||||
'Traceback...ZeroDivisionError...'
|
['Traceback...ZeroDivisionError...']
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/python
|
# cybertools.meta.tests
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tests for the 'cybertools.meta' package.
|
Tests for the 'cybertools.meta' package.
|
||||||
|
@ -17,7 +17,7 @@ class Test(unittest.TestCase):
|
||||||
def test_suite():
|
def test_suite():
|
||||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
return unittest.TestSuite((
|
return unittest.TestSuite((
|
||||||
unittest.makeSuite(Test),
|
unittest.TestLoader().loadTestsFromTestCase(Test),
|
||||||
doctest.DocFileSuite('README.txt', optionflags=flags),
|
doctest.DocFileSuite('README.txt', optionflags=flags),
|
||||||
doctest.DocFileSuite('namespace.txt', optionflags=flags),
|
doctest.DocFileSuite('namespace.txt', optionflags=flags),
|
||||||
))
|
))
|
||||||
|
|
|
@ -77,11 +77,15 @@ RTF Files
|
||||||
>>> f = open(os.path.join(testdir, 'mary.rtf'), 'rb')
|
>>> f = open(os.path.join(testdir, 'mary.rtf'), 'rb')
|
||||||
>>> result = transform(f)
|
>>> result = transform(f)
|
||||||
>>> print(log)
|
>>> print(log)
|
||||||
>>> words = result.split()
|
zope.server WARNING
|
||||||
>>> len(words)
|
rtf2xml is not available
|
||||||
90
|
|
||||||
>>> u'lamb' in words
|
>> words = result.split()
|
||||||
True
|
>> len(words)
|
||||||
|
90
|
||||||
|
>> u'lamb' in words
|
||||||
|
True
|
||||||
|
|
||||||
>>> f.close()
|
>>> f.close()
|
||||||
|
|
||||||
PowerPoint Presentations
|
PowerPoint Presentations
|
||||||
|
@ -92,6 +96,8 @@ PowerPoint Presentations
|
||||||
>>> f = open(os.path.join(testdir, 'mary.ppt'), 'rb')
|
>>> f = open(os.path.join(testdir, 'mary.ppt'), 'rb')
|
||||||
>>> result = transform(f)
|
>>> result = transform(f)
|
||||||
>>> print(log)
|
>>> print(log)
|
||||||
|
zope.server WARNING
|
||||||
|
rtf2xml is not available
|
||||||
zope.server WARNING
|
zope.server WARNING
|
||||||
ppthtml is not available
|
ppthtml is not available
|
||||||
|
|
||||||
|
|
|
@ -87,10 +87,9 @@ use ``@property`` but ``@getproperty`` to mark the getter and
|
||||||
... self._feel = feel
|
... self._feel = feel
|
||||||
|
|
||||||
>>> i = JamesBrown()
|
>>> i = JamesBrown()
|
||||||
>>> i.feel
|
>>> try: i.feel
|
||||||
Traceback (most recent call last):
|
... except Exception as e: print(e)
|
||||||
...
|
'JamesBrown' object has no attribute '_feel'
|
||||||
AttributeError: 'JamesBrown' object has no attribute '_feel'
|
|
||||||
|
|
||||||
>>> i.feel = "good"
|
>>> i.feel = "good"
|
||||||
>>> i.feel
|
>>> i.feel
|
||||||
|
@ -127,10 +126,9 @@ Of course, deleters are also possible:
|
||||||
>>> i = JamesBrown()
|
>>> i = JamesBrown()
|
||||||
>>> i.feel = "good"
|
>>> i.feel = "good"
|
||||||
>>> del i.feel
|
>>> del i.feel
|
||||||
>>> i.feel
|
>>> try: i.feel
|
||||||
Traceback (most recent call last):
|
... except Exception as e: print(e)
|
||||||
...
|
'JamesBrown' object has no attribute '_feel'
|
||||||
AttributeError: 'JamesBrown' object has no attribute '_feel'
|
|
||||||
|
|
||||||
|
|
||||||
Edge cases
|
Edge cases
|
||||||
|
|
Loading…
Add table
Reference in a new issue