Skip to content

Commit fb486bf

Browse files
committed
Modernize code a bit
1 parent a355f46 commit fb486bf

File tree

12 files changed

+35
-45
lines changed

12 files changed

+35
-45
lines changed

webware/Examples/AjaxPage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def quoteJs(what):
1818
"""Return quoted JavaScript string corresponding to the Python object."""
1919
if isinstance(what, bool):
2020
ret = str(what).lower()
21-
elif isinstance(what, (int, float, PyJs)):
21+
elif isinstance(what, int | float | PyJs):
2222
ret = str(what)
2323
else:
2424
ret = "'{}'".format(str(what).replace('\\', '\\\\').replace(

webware/Examples/Introspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def writeContent(self):
2020
self.writeln('</table>')
2121

2222
def pair(self, key, value):
23-
if isinstance(value, (list, tuple)):
23+
if isinstance(value, list | tuple):
2424
value = ', '.join(map(str, value))
2525
value = self.htmlEncode(str(value))
2626
self.writeln(
@@ -29,6 +29,6 @@ def pair(self, key, value):
2929

3030
def list(self, codeString):
3131
value = eval(codeString)
32-
if not isinstance(value, (list, tuple)):
32+
if not isinstance(value, list | tuple):
3333
value = '<em>not a list or a tuple</em>'
3434
self.pair(codeString, value)

webware/Examples/YattagDemo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ def demoForm(self):
6363
with tag('p', klass='success'):
6464
text('Congratulations! You have sent the following message:')
6565
with tag('div', klass='output'):
66-
with tag('p'):
67-
with tag('strong'):
68-
text(subject)
66+
with tag('p'), tag('strong'):
67+
text(subject)
6968
with tag('p'):
7069
text(message)
7170
with tag('a', href='YattagDemo'):

webware/ExceptionHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def emailException(self, htmlErrMsg):
506506
headers['Subject'] = '{} {}: {}'.format(
507507
headers.get('Subject', '[Webware Error]'), *sys.exc_info()[:2])
508508
for header, value in headers.items():
509-
if isinstance(value, (list, tuple)):
509+
if isinstance(value, list | tuple):
510510
value = ','.join(value)
511511
message.add_header(header, value)
512512

webware/HTTPResponse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ def setCookie(
134134
elif t.startswith('+'):
135135
t = time() + timeDecode(t[1:])
136136
if t:
137-
if isinstance(t, (int, float)):
137+
if isinstance(t, int | float):
138138
t = gmtime(t)
139-
if isinstance(t, (tuple, struct_time)):
139+
elif isinstance(t, tuple | struct_time):
140140
t = strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
141-
if isinstance(t, timedelta):
141+
elif isinstance(t, timedelta):
142142
t = datetime.now() + t
143-
if isinstance(t, datetime):
143+
elif isinstance(t, datetime):
144144
d = t.utcoffset()
145145
if d is None:
146146
d = localTimeDelta()

webware/MiscUtils/DataTable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def __init__(self, table, values=None, headings=None):
702702
self._headings = table.headings() if headings is None else headings
703703
self._nameToIndexMap = table.nameToIndexMap()
704704
if values is not None:
705-
if isinstance(values, (list, tuple)):
705+
if isinstance(values, list | tuple):
706706
self.initFromSequence(values)
707707
elif isinstance(values, dict):
708708
self.initFromDict(values)

webware/MiscUtils/MixIn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def foo(self):
8585
continue # built in or descriptor
8686
else:
8787
member = getattr(mixInClass, name)
88-
if isinstance(member, (FunctionType, MethodType)):
88+
if isinstance(member, FunctionType | MethodType):
8989
if mixInSuperMethods:
9090
if hasattr(pyClass, name):
9191
origMember = getattr(pyClass, name)

webware/MiscUtils/PickleCache.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@
4747
import sys
4848
from time import sleep
4949
from pprint import pprint
50-
try:
51-
from pickle import load, dump, HIGHEST_PROTOCOL as maxPickleProtocol
52-
except ImportError:
53-
from pickle import load, dump, HIGHEST_PROTOCOL as maxPickleProtocol
50+
from pickle import load, dump, HIGHEST_PROTOCOL as maxPickleProtocol
5451

5552
verbose = False
5653

webware/MiscUtils/Tests/BenchCSVParser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import sys
22
import time
33
from glob import glob
4-
try:
5-
from cProfile import Profile
6-
except ImportError:
7-
from profile import Profile
4+
from cProfile import Profile
85

96
from MiscUtils.CSVParser import CSVParser
107

webware/MiscUtils/Tests/BenchDataTable.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import sys
44
import time
55
from glob import glob
6-
try:
7-
from cProfile import Profile
8-
except ImportError:
9-
from profile import Profile
6+
from cProfile import Profile
107

118
from MiscUtils.DataTable import DataTable
129

0 commit comments

Comments
 (0)