Merge branch 'annotation_quoting'

* annotation_quoting:
  Examples: Unify string quoting in the Python sources
  Test-suite: Unify string quoting in the Python sources
  Tools: Unify string quoting in the Python sources
  Generator: Unify string quoting in generated Python sources
  Generator: Remove trailing whitespaces in the Python module
This commit is contained in:
William S Fulton 2019-07-18 07:23:06 +01:00
commit c8b1eed8ce
36 changed files with 200 additions and 200 deletions

View file

@ -11,7 +11,7 @@ def run_except_on_windows(commandline, env=None):
print(" Starting subtest " + os.path.basename(__file__)) print(" Starting subtest " + os.path.basename(__file__))
# Package brave found under one path # Package brave found under one path
sys.path.insert(0, 'path1') sys.path.insert(0, "path1")
from brave import robin from brave import robin
print(" Finished from brave import robin") print(" Finished from brave import robin")

View file

@ -11,7 +11,7 @@ def run_except_on_windows(commandline, env=None):
print(" Finished running: " + commandline) print(" Finished running: " + commandline)
def copyMods(): def copyMods():
dirs = ['path1', 'path2', 'path3'] dirs = ["path1", "path2", "path3"]
# Clean out any old package paths # Clean out any old package paths
for d in dirs: for d in dirs:
@ -20,20 +20,20 @@ def copyMods():
for d in dirs: for d in dirs:
os.mkdir(d) os.mkdir(d)
os.mkdir(os.path.join(d, 'brave')) os.mkdir(os.path.join(d, "brave"))
shutil.copy('robin.py', os.path.join('path1', 'brave')) shutil.copy("robin.py", os.path.join("path1", "brave"))
subprocess.check_call('cp _robin.* ' + os.path.join('path1', 'brave'), shell=True) subprocess.check_call("cp _robin.* " + os.path.join("path1", "brave"), shell=True)
shutil.copy('robin.py', os.path.join('path2', 'brave')) shutil.copy("robin.py", os.path.join("path2", "brave"))
subprocess.check_call('cp _robin.* ' + os.path.join('path3', 'brave'), shell=True) subprocess.check_call("cp _robin.* " + os.path.join("path3", "brave"), shell=True)
mkzip() mkzip()
def mkzip(): def mkzip():
zf = zipfile.ZipFile("path4.zip", "w") zf = zipfile.ZipFile("path4.zip", "w")
zf.writestr("brave/", b'') zf.writestr("brave/", b"")
zf.write('robin.py', 'brave/robin.py') zf.write("robin.py", "brave/robin.py")
zf.close() zf.close()

View file

@ -12,8 +12,8 @@ print(" Starting subtest " + os.path.basename(__file__))
# Package brave split into two paths. # Package brave split into two paths.
# path2/brave/robin.py and path3/brave/_robin.so # path2/brave/robin.py and path3/brave/_robin.so
sys.path.insert(0, 'path2') sys.path.insert(0, "path2")
sys.path.insert(0, 'path3') sys.path.insert(0, "path3")
from brave import robin from brave import robin
print(" Finished from brave import robin") print(" Finished from brave import robin")

View file

@ -12,8 +12,8 @@ print(" Starting subtest " + os.path.basename(__file__))
# Package brave split into two paths. # Package brave split into two paths.
# brave/robin.py (in path4.zip) and path3/brave/_robin.so # brave/robin.py (in path4.zip) and path3/brave/_robin.so
sys.path.insert(0, 'path4.zip') sys.path.insert(0, "path4.zip")
sys.path.insert(0, 'path3') sys.path.insert(0, "path3")
from brave import robin from brave import robin
print(" Finished from brave import robin") print(" Finished from brave import robin")

View file

@ -1,5 +1,5 @@
import sys import sys
sys.path.append('..') sys.path.append("..")
import harness import harness

View file

@ -1,5 +1,5 @@
import sys import sys
sys.path.append('..') sys.path.append("..")
import harness import harness

View file

@ -17,16 +17,16 @@ def run(proc):
except IndexError: except IndexError:
proc = Popen( proc = Popen(
[sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE) [sys.executable, "runme.py", "Simple_baseline"], stdout=PIPE)
(stdout, stderr) = proc.communicate() (stdout, stderr) = proc.communicate()
print stdout print stdout
proc = Popen( proc = Popen(
[sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE) [sys.executable, "runme.py", "Simple_optimized"], stdout=PIPE)
(stdout, stderr) = proc.communicate() (stdout, stderr) = proc.communicate()
print stdout print stdout
proc = Popen( proc = Popen(
[sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE) [sys.executable, "runme.py", "Simple_builtin"], stdout=PIPE)
(stdout, stderr) = proc.communicate() (stdout, stderr) = proc.communicate()
print stdout print stdout

View file

@ -1,5 +1,5 @@
import sys import sys
sys.path.append('..') sys.path.append("..")
import harness import harness

View file

@ -1,5 +1,5 @@
import sys import sys
sys.path.append('..') sys.path.append("..")
import harness import harness

View file

@ -1,5 +1,5 @@
import sys import sys
sys.path.append('..') sys.path.append("..")
import harness import harness

View file

@ -1,21 +1,21 @@
from argcargvtest import * from argcargvtest import *
largs = ['hi', 'hola', 'hello'] largs = ["hi", "hola", "hello"]
if mainc(largs) != 3: if mainc(largs) != 3:
raise RuntimeError("bad main typemap") raise RuntimeError("bad main typemap")
targs = ('hi', 'hola') targs = ("hi", "hola")
if mainv(targs, 1) != 'hola': if mainv(targs, 1) != "hola":
print(mainv(targs, 1)) print(mainv(targs, 1))
raise RuntimeError("bad main typemap") raise RuntimeError("bad main typemap")
targs = ('hi', 'hola') targs = ("hi", "hola")
if mainv(targs, 1) != 'hola': if mainv(targs, 1) != "hola":
raise RuntimeError("bad main typemap") raise RuntimeError("bad main typemap")
try: try:
error = 0 error = 0
mainv('hello', 1) mainv("hello", 1)
error = 1 error = 1
except TypeError: except TypeError:
pass pass

View file

@ -1,26 +1,26 @@
from char_binary import * from char_binary import *
t = Test() t = Test()
if t.strlen('hile') != 4: if t.strlen("hile") != 4:
print t.strlen('hile') print t.strlen("hile")
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError, "bad multi-arg typemap"
if t.ustrlen('hile') != 4: if t.ustrlen("hile") != 4:
print t.ustrlen('hile') print t.ustrlen("hile")
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError, "bad multi-arg typemap"
if t.strlen('hil\0') != 4: if t.strlen("hil\0") != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError, "bad multi-arg typemap"
if t.ustrlen('hil\0') != 4: if t.ustrlen("hil\0") != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError, "bad multi-arg typemap"
# #
# creating a raw char* # creating a raw char*
# #
pc = new_pchar(5) pc = new_pchar(5)
pchar_setitem(pc, 0, 'h') pchar_setitem(pc, 0, "h")
pchar_setitem(pc, 1, 'o') pchar_setitem(pc, 1, "o")
pchar_setitem(pc, 2, 'l') pchar_setitem(pc, 2, "l")
pchar_setitem(pc, 3, 'a') pchar_setitem(pc, 3, "a")
pchar_setitem(pc, 4, 0) pchar_setitem(pc, 4, 0)

View file

@ -1,10 +1,10 @@
def check(got, expected, expected_builtin=None): def check(got, expected, expected_builtin=None):
if got is None: # Absence of comment is equivalent to empty comment. if got is None: # Absence of comment is equivalent to empty comment.
got = '' got = ""
if got != expected: if got != expected:
import re import re
p = re.compile(r'^[+-]([^+-].*\S)?(\s+)$', re.M) p = re.compile(r"^[+-]([^+-].*\S)?(\s+)$", re.M)
def make_trailing_spaces_visible(str): def make_trailing_spaces_visible(str):
def replace_trailing_spaces(match): def replace_trailing_spaces(match):

View file

@ -1,10 +1,10 @@
from cpp17_u8_char_literals import * from cpp17_u8_char_literals import *
if cvar.a != 'a': if cvar.a != "a":
raise RuntimeError raise RuntimeError
if cvar.u != 'u': if cvar.u != "u":
raise RuntimeError raise RuntimeError
if cvar.u8 != '8': if cvar.u8 != "8":
raise RuntimeError raise RuntimeError

View file

@ -170,23 +170,23 @@ def run(module_name):
if default_args.CDA().cdefaultargs_test2() != 1: if default_args.CDA().cdefaultargs_test2() != 1:
raise RuntimeError raise RuntimeError
if default_args.chartest1() != 'x': if default_args.chartest1() != "x":
raise RuntimeError raise RuntimeError
if default_args.chartest2() != '\0': if default_args.chartest2() != "\0":
raise RuntimeError raise RuntimeError
if default_args.chartest3() != '\1': if default_args.chartest3() != "\1":
raise RuntimeError raise RuntimeError
if default_args.chartest4() != '\n': if default_args.chartest4() != "\n":
raise RuntimeError raise RuntimeError
if default_args.chartest5() != 'B': if default_args.chartest5() != "B":
raise RuntimeError raise RuntimeError
if default_args.chartest6() != 'C': if default_args.chartest6() != "C":
raise RuntimeError raise RuntimeError
if __name__ == "__main__": if __name__ == "__main__":
run('default_args') run("default_args")

View file

@ -75,7 +75,7 @@ b = launder(a)
try: try:
b.pong() b.pong()
except MyException, e: except MyException, e:
if e.msg == 'foobar': if e.msg == "foobar":
ok = 1 ok = 1
else: else:
print "Unexpected error message: %s" % str(e) print "Unexpected error message: %s" % str(e)

View file

@ -44,7 +44,7 @@ comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.getConnection),
comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.getFirstLetter), comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.getFirstLetter),
r'' r""
) )
comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.ClassWithNestedEnum), comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.ClassWithNestedEnum),
@ -73,7 +73,7 @@ comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.isNoSpaceValidB),
) )
comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.isNoSpaceValidC), comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.isNoSpaceValidC),
r'' r""
) )
comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.backslashA), comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.backslashA),

View file

@ -2,7 +2,7 @@ from ignore_parameter import *
def check(a, b): def check(a, b):
if a != b: if a != b:
raise RuntimeError('"%s" != "%s"' % (a, b)) raise RuntimeError("'%s' != '%s'" % (a, b))
check(jaguar(200, 0), "hello") check(jaguar(200, 0), "hello")
check(lotus("foo", 1), 101) check(lotus("foo", 1), 101)

View file

@ -18,10 +18,10 @@ if test4("hello") != "hello-suffix":
print test4("hello") print test4("hello")
raise RuntimeError raise RuntimeError
if test5(4) != 'xxxx': if test5(4) != "xxxx":
raise RuntimeError raise RuntimeError
if test6(10) != 'xxxxx': if test6(10) != "xxxxx":
raise RuntimeError raise RuntimeError
if test7() != "Hello world!": if test7() != "Hello world!":

View file

@ -15,10 +15,10 @@ if test3("hello") != u"hello-suffix":
if test4("hello") != u"hello-suffix": if test4("hello") != u"hello-suffix":
raise RuntimeError raise RuntimeError
if test5(4) != u'xxxx': if test5(4) != u"xxxx":
raise RuntimeError raise RuntimeError
if test6(10) != u'xxxxx': if test6(10) != u"xxxxx":
raise RuntimeError raise RuntimeError
if test7() != u"Hello world!": if test7() != u"Hello world!":

View file

@ -90,5 +90,5 @@ sum = ()
for i in s: for i in s:
sum = sum + (i,) sum = sum + (i,)
if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)): if (len(sum) != 3 or (not 1 in sum) or (not "hello" in sum) or (not (1, 2) in sum)):
raise RuntimeError raise RuntimeError

View file

@ -19,7 +19,7 @@ if li_std_string_extra.test_const_reference(x) != x:
s = li_std_string_extra.string("he") s = li_std_string_extra.string("he")
#s += "ll" #s += "ll"
# s.append('o') # s.append("o")
s = s + "llo" s = s + "llo"
if s != x: if s != x:

View file

@ -91,7 +91,7 @@ if v.size() != 0:
v = vecStr(["hello ", "world"]) v = vecStr(["hello ", "world"])
if v[0] != 'hello world': if v[0] != "hello world":
raise RuntimeError, "bad std::string+std::vector" raise RuntimeError, "bad std::string+std::vector"

View file

@ -33,7 +33,7 @@ if ref_double(3.5) != 3.5:
if ref_bool(True) != True: if ref_bool(True) != True:
raise RuntimeError raise RuntimeError
if ref_char('x') != 'x': if ref_char("x") != "x":
raise RuntimeError raise RuntimeError
if ref_over(0) != 0: if ref_over(0) != 0:

View file

@ -227,7 +227,7 @@ t.var_paramc = sct_paramc
t.v_check() t.v_check()
# this value contains a '0' char! # this value contains a '0' char!
if def_namet != 'hola': if def_namet != "hola":
print "bad namet", def_namet print "bad namet", def_namet
raise RuntimeError raise RuntimeError
@ -236,54 +236,54 @@ if t.var_namet != def_namet:
print "bad namet", t.var_namet, def_namet print "bad namet", t.var_namet, def_namet
raise RuntimeError raise RuntimeError
t.var_namet = 'hola' t.var_namet = "hola"
if t.var_namet != 'hola': if t.var_namet != "hola":
print "bad namet", t.var_namet print "bad namet", t.var_namet
raise RuntimeError raise RuntimeError
t.var_namet = 'hol' t.var_namet = "hol"
if t.var_namet != 'hol': if t.var_namet != "hol":
# if t.var_namet != 'hol\0\0': # if t.var_namet != "hol\0\0":
print "bad namet", t.var_namet print "bad namet", t.var_namet
raise RuntimeError raise RuntimeError
cvar.var_char = '\0' cvar.var_char = "\0"
if cvar.var_char != '\0': if cvar.var_char != "\0":
raise RuntimeError, "bad char '0' case" raise RuntimeError, "bad char '0' case"
cvar.var_char = 0 cvar.var_char = 0
if cvar.var_char != '\0': if cvar.var_char != "\0":
raise RuntimeError, "bad char '0' case" raise RuntimeError, "bad char '0' case"
cvar.var_namet = '\0' cvar.var_namet = "\0"
# if cvar.var_namet != '\0\0\0\0\0': # if cvar.var_namet != "\0\0\0\0\0":
if cvar.var_namet != '': if cvar.var_namet != "":
print 'hola', '', cvar.var_namet print "hola", "", cvar.var_namet
raise RuntimeError, "bad char '\0' case" raise RuntimeError, "bad char '\0' case"
cvar.var_namet = '' cvar.var_namet = ""
# if cvar.var_namet != '\0\0\0\0\0': # if cvar.var_namet != "\0\0\0\0\0":
if cvar.var_namet != '': if cvar.var_namet != "":
raise RuntimeError, "bad char empty case" raise RuntimeError, "bad char empty case"
cvar.var_pchar = None cvar.var_pchar = None
if cvar.var_pchar != None: if cvar.var_pchar != None:
raise RuntimeError, "bad None case" raise RuntimeError, "bad None case"
cvar.var_pchar = '' cvar.var_pchar = ""
if cvar.var_pchar != '': if cvar.var_pchar != "":
print '%c' % (cvar.var_pchar[0],) print "%c" % (cvar.var_pchar[0],)
raise RuntimeError, "bad char empty case" raise RuntimeError, "bad char empty case"
cvar.var_pcharc = None cvar.var_pcharc = None
if cvar.var_pcharc != None: if cvar.var_pcharc != None:
raise RuntimeError, "bad None case" raise RuntimeError, "bad None case"
cvar.var_pcharc = '' cvar.var_pcharc = ""
if cvar.var_pcharc != '': if cvar.var_pcharc != "":
raise RuntimeError, "bad char empty case" raise RuntimeError, "bad char empty case"
@ -291,10 +291,10 @@ if cvar.var_pcharc != '':
# creating a raw char* # creating a raw char*
# #
pc = new_pchar(5) pc = new_pchar(5)
pchar_setitem(pc, 0, 'h') pchar_setitem(pc, 0, "h")
pchar_setitem(pc, 1, 'o') pchar_setitem(pc, 1, "o")
pchar_setitem(pc, 2, 'l') pchar_setitem(pc, 2, "l")
pchar_setitem(pc, 3, 'a') pchar_setitem(pc, 3, "a")
pchar_setitem(pc, 4, 0) pchar_setitem(pc, 4, 0)
@ -331,7 +331,7 @@ if error:
try: try:
error = 0 error = 0
a = t.var_char a = t.var_char
t.var_char = '23' t.var_char = "23"
error = 1 error = 1
except TypeError: except TypeError:
if a != t.var_char: if a != t.var_char:
@ -393,7 +393,7 @@ if error:
try: try:
error = 0 error = 0
a = t.var_namet a = t.var_namet
t.var_namet = '123456' t.var_namet = "123456"
error = 1 error = 1
except TypeError: except TypeError:
if a != t.var_namet: if a != t.var_namet:
@ -410,11 +410,11 @@ if t.var_namet != t2.var_namet:
raise RuntimeError, "bad SWIGTYPE* typemap" raise RuntimeError, "bad SWIGTYPE* typemap"
if cvar.fixsize != 'ho\0la\0\0\0': if cvar.fixsize != "ho\0la\0\0\0":
raise RuntimeError, "bad FIXSIZE typemap" raise RuntimeError, "bad FIXSIZE typemap"
cvar.fixsize = 'ho' cvar.fixsize = "ho"
if cvar.fixsize != 'ho\0\0\0\0\0\0': if cvar.fixsize != "ho\0\0\0\0\0\0":
raise RuntimeError, "bad FIXSIZE typemap" raise RuntimeError, "bad FIXSIZE typemap"
@ -487,26 +487,26 @@ def checkType(t, e, val, delta):
"""t = Test object, e = type name (e.g. ulong), val = max or min allowed value, delta = +1 for max, -1 for min""" """t = Test object, e = type name (e.g. ulong), val = max or min allowed value, delta = +1 for max, -1 for min"""
error = 0 error = 0
# Set the extreme valid value for var_* # Set the extreme valid value for var_*
setattr(t, 'var_' + e, val) setattr(t, "var_" + e, val)
# Make sure it was set properly and works properly in the val_* and ref_* methods # Make sure it was set properly and works properly in the val_* and ref_* methods
if getattr(t, 'var_' + e) != val or getattr(t, 'val_' + e)(val) != val or getattr(t, 'ref_' + e)(val) != val: if getattr(t, "var_" + e) != val or getattr(t, "val_" + e)(val) != val or getattr(t, "ref_" + e)(val) != val:
error = 1 error = 1
# Make sure setting a more extreme value fails without changing the value # Make sure setting a more extreme value fails without changing the value
try: try:
a = getattr(t, 'var_' + e) a = getattr(t, "var_" + e)
setattr(t, 'var_' + e, val + delta) setattr(t, "var_" + e, val + delta)
error = 1 error = 1
except OverflowError: except OverflowError:
if a != getattr(t, 'var_' + e): if a != getattr(t, "var_" + e):
error = 1 error = 1
# Make sure the val_* and ref_* methods fail with a more extreme value # Make sure the val_* and ref_* methods fail with a more extreme value
try: try:
getattr(t, 'val_' + e)(val + delta) getattr(t, "val_" + e)(val + delta)
error = 1 error = 1
except OverflowError: except OverflowError:
pass pass
try: try:
getattr(t, 'ref_' + e)(val + delta) getattr(t, "ref_" + e)(val + delta)
error = 1 error = 1
except OverflowError: except OverflowError:
pass pass
@ -518,16 +518,16 @@ def checkFull(t, e, maxval, minval):
checkType(t, e, maxval, 1) checkType(t, e, maxval, 1)
checkType(t, e, minval, -1) checkType(t, e, minval, -1)
checkFull(t, 'llong', maxllong, minllong) checkFull(t, "llong", maxllong, minllong)
checkFull(t, 'long', maxlong, minlong) checkFull(t, "long", maxlong, minlong)
checkFull(t, 'int', maxint, minint) checkFull(t, "int", maxint, minint)
checkFull(t, 'short', maxshort, minshort) checkFull(t, "short", maxshort, minshort)
checkFull(t, 'schar', maxchar, minchar) checkFull(t, "schar", maxchar, minchar)
checkFull(t, 'ullong', maxullong, 0) checkFull(t, "ullong", maxullong, 0)
checkFull(t, 'ulong', maxulong, 0) checkFull(t, "ulong", maxulong, 0)
checkFull(t, 'uint', maxuint, 0) checkFull(t, "uint", maxuint, 0)
checkFull(t, 'ushort', maxushort, 0) checkFull(t, "ushort", maxushort, 0)
checkFull(t, 'uchar', maxuchar, 0) checkFull(t, "uchar", maxuchar, 0)
def checkOverload(t, name, val, delta, prevval, limit): def checkOverload(t, name, val, delta, prevval, limit):
""" """
@ -556,16 +556,16 @@ def checkOverload(t, name, val, delta, prevval, limit):
raise RuntimeError, "bad " + name + " typemap" raise RuntimeError, "bad " + name + " typemap"
# Check that overloading works: uchar > schar > ushort > short > uint > int > ulong > long > ullong > llong # Check that overloading works: uchar > schar > ushort > short > uint > int > ulong > long > ullong > llong
checkOverload(t, 'uchar', maxuchar, +1, 0, maxullong) checkOverload(t, "uchar", maxuchar, +1, 0, maxullong)
checkOverload(t, 'ushort', maxushort, +1, maxuchar, maxullong) checkOverload(t, "ushort", maxushort, +1, maxuchar, maxullong)
checkOverload(t, 'uint', maxuint, +1, maxushort, maxullong) checkOverload(t, "uint", maxuint, +1, maxushort, maxullong)
checkOverload(t, 'ulong', maxulong, +1, maxuint, maxullong) checkOverload(t, "ulong", maxulong, +1, maxuint, maxullong)
checkOverload(t, 'ullong', maxullong, +1, maxulong, maxullong) checkOverload(t, "ullong", maxullong, +1, maxulong, maxullong)
checkOverload(t, 'schar', minchar, -1, 0, minllong) checkOverload(t, "schar", minchar, -1, 0, minllong)
checkOverload(t, 'short', minshort, -1, minchar, minllong) checkOverload(t, "short", minshort, -1, minchar, minllong)
checkOverload(t, 'int', minint, -1, minshort, minllong) checkOverload(t, "int", minint, -1, minshort, minllong)
checkOverload(t, 'long', minlong, -1, minint, minllong) checkOverload(t, "long", minlong, -1, minint, minllong)
checkOverload(t, 'llong', minllong, -1, minlong, minllong) checkOverload(t, "llong", minllong, -1, minlong, minllong)
# Make sure that large ints can be converted to doubles properly # Make sure that large ints can be converted to doubles properly
if val_double(sys.maxint + 1) != float(sys.maxint + 1): if val_double(sys.maxint + 1) != float(sys.maxint + 1):

View file

@ -14,13 +14,13 @@ if len(sys.argv) >= 2 and sys.argv[1] == "benchmark":
k = 1000000 # number of times to execute the functions k = 1000000 # number of times to execute the functions
t = time.time() t = time.time()
a = bytearray(b'hello world') a = bytearray(b"hello world")
for i in range(k): for i in range(k):
python_pybuffer.title1(a) python_pybuffer.title1(a)
print "Time used by bytearray:", time.time() - t print "Time used by bytearray:", time.time() - t
t = time.time() t = time.time()
b = 'hello world' b = "hello world"
for i in range(k): for i in range(k):
python_pybuffer.title2(b) python_pybuffer.title2(b)
print "Time used by string:", time.time() - t print "Time used by string:", time.time() - t
@ -30,7 +30,7 @@ else:
buf2 = bytearray(50) buf2 = bytearray(50)
python_pybuffer.func1(buf1) python_pybuffer.func1(buf1)
check(buf1 == b'a' * 10) check(buf1 == b"a" * 10)
python_pybuffer.func2(buf2) python_pybuffer.func2(buf2)
check(buf2.startswith(b"Hello world!\x00")) check(buf2.startswith(b"Hello world!\x00"))
@ -43,4 +43,4 @@ else:
buf3 = bytearray(b"hello") buf3 = bytearray(b"hello")
python_pybuffer.title1(buf3) python_pybuffer.title1(buf3)
check(buf3 == b'Hello') check(buf3 == b"Hello")

View file

@ -1,8 +1,8 @@
import python_strict_unicode import python_strict_unicode
test_bytes = b'hello \x01world\x99' test_bytes = b"hello \x01world\x99"
BYTES = b'BYTES' BYTES = b"BYTES"
test_unicode = u'h\udce9llo w\u00f6rld' test_unicode = u"h\udce9llo w\u00f6rld"
# Test that byte string inputs and outputs work as expected # Test that byte string inputs and outputs work as expected
bdbl = python_strict_unicode.double_str(test_bytes) bdbl = python_strict_unicode.double_str(test_bytes)
@ -20,12 +20,12 @@ if type(bout) != type(BYTES):
udbl = python_strict_unicode.double_wstr(test_unicode) udbl = python_strict_unicode.double_wstr(test_unicode)
if udbl != test_unicode + test_unicode: if udbl != test_unicode + test_unicode:
raise RuntimeError("Failed to double wide string") raise RuntimeError("Failed to double wide string")
if type(udbl) != type(u''): if type(udbl) != type(u""):
raise RuntimeError("Wrong type output for wide string") raise RuntimeError("Wrong type output for wide string")
uout = python_strict_unicode.same_wstr(test_unicode) uout = python_strict_unicode.same_wstr(test_unicode)
if uout != test_unicode: if uout != test_unicode:
raise RuntimeError("Failed to copy wchar_t*") raise RuntimeError("Failed to copy wchar_t*")
if type(uout) != type(u''): if type(uout) != type(u""):
raise RuntimeError("Wrong type output for wchar_t*") raise RuntimeError("Wrong type output for wchar_t*")
# Test that overloading is handled properly # Test that overloading is handled properly
@ -35,9 +35,9 @@ if bovr != BYTES:
if type(bovr) != type(BYTES): if type(bovr) != type(BYTES):
raise RuntimeError("Wrong type output from overload") raise RuntimeError("Wrong type output from overload")
uovr = python_strict_unicode.overload(test_unicode) uovr = python_strict_unicode.overload(test_unicode)
if uovr != u'UNICODE': if uovr != u"UNICODE":
raise RuntimeError("Failed to return unicode from overload") raise RuntimeError("Failed to return unicode from overload")
if type(uovr) != type(u''): if type(uovr) != type(u""):
raise RuntimeERror("Wrong type output from overload") raise RuntimeERror("Wrong type output from overload")
# Test that bytes aren't accepted as wide strings and unicode isn't accepted as narrow strings # Test that bytes aren't accepted as wide strings and unicode isn't accepted as narrow strings

View file

@ -13,8 +13,8 @@ cvar.var_bool = createref_bool(True)
if value_bool(cvar.var_bool) != True: if value_bool(cvar.var_bool) != True:
raise RuntimeError raise RuntimeError
cvar.var_char = createref_char('w') cvar.var_char = createref_char("w")
if value_char(cvar.var_char) != 'w': if value_char(cvar.var_char) != "w":
raise RuntimeError raise RuntimeError
cvar.var_unsigned_char = createref_unsigned_char(10) cvar.var_unsigned_char = createref_unsigned_char(10)

View file

@ -60,9 +60,9 @@ if mi[0][1] != mc[0][1]:
map = {} map = {}
map['hello'] = 1 map["hello"] = 1
map['hi'] = 2 map["hi"] = 2
map['3'] = 2 map["3"] = 2
imap = std_containers.mapident(map) imap = std_containers.mapident(map)
for k in map: for k in map:
@ -70,13 +70,13 @@ for k in map:
raise RuntimeError, "bad map" raise RuntimeError, "bad map"
# Test __contains__ (required for 'x in y' to work) # Test __contains__ (required for 'x in y' to work)
if not imap.__contains__('hello'): if not imap.__contains__("hello"):
raise RuntimeError("hello imap.__contains__") raise RuntimeError("hello imap.__contains__")
if 'hello' not in imap: if "hello" not in imap:
raise RuntimeError("hello not in imap") raise RuntimeError("hello not in imap")
if imap.__contains__('oops'): if imap.__contains__("oops"):
raise RuntimeError("oops imap.__contains__") raise RuntimeError("oops imap.__contains__")
if 'oops' in imap: if "oops" in imap:
raise RuntimeError("oops in imap") raise RuntimeError("oops in imap")
mapc = {} mapc = {}

View file

@ -15,11 +15,11 @@ lthis = long(a.this)
# match pointer value, but deal with leading zeros on 8/16 bit systems and # match pointer value, but deal with leading zeros on 8/16 bit systems and
# different C++ compilers interpretation of %p # different C++ compilers interpretation of %p
xstr1 = "%016X" % (lthis,) xstr1 = "%016X" % (lthis,)
xstr1 = str.lstrip(xstr1, '0') xstr1 = str.lstrip(xstr1, "0")
xstr2 = pointer_str(a) xstr2 = pointer_str(a)
xstr2 = str.replace(xstr2, "0x", "") xstr2 = str.replace(xstr2, "0x", "")
xstr2 = str.replace(xstr2, "0X", "") xstr2 = str.replace(xstr2, "0X", "")
xstr2 = str.lstrip(xstr2, '0') xstr2 = str.lstrip(xstr2, "0")
xstr2 = str.upper(xstr2) xstr2 = str.upper(xstr2)
if xstr1 != xstr2: if xstr1 != xstr2:

View file

@ -11,8 +11,8 @@ except:
print d, "is not an instance" print d, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % d s = "%s" % d
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print d, "is not an ArithUnaryFunction" print d, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -23,8 +23,8 @@ except:
print e, "is not an instance" print e, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % e s = "%s" % e
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print e, "is not an ArithUnaryFunction" print e, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -40,8 +40,8 @@ except:
print c, "is not an instance" print c, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % c s = "%s" % c
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print c, "is not an ArithUnaryFunction" print c, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -52,8 +52,8 @@ except:
print f, "is not an instance" print f, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % f s = "%s" % f
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print f, "is not an ArithUnaryFunction" print f, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -68,8 +68,8 @@ except:
print g, "is not an instance" print g, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % g s = "%s" % g
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print g, "is not an ArithUnaryFunction" print g, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -81,8 +81,8 @@ except:
print h, "is not an instance" print h, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % h s = "%s" % h
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print h, "is not an ArithUnaryFunction" print h, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError

View file

@ -11,8 +11,8 @@ except:
print d, "is not an instance" print d, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % d s = "%s" % d
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print d, "is not an ArithUnaryFunction" print d, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -23,8 +23,8 @@ except:
print e, "is not an instance" print e, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % e s = "%s" % e
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print e, "is not an ArithUnaryFunction" print e, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -40,8 +40,8 @@ except:
print c, "is not an instance" print c, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % c s = "%s" % c
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print c, "is not an ArithUnaryFunction" print c, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -52,8 +52,8 @@ except:
print f, "is not an instance" print f, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % f s = "%s" % f
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print f, "is not an ArithUnaryFunction" print f, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -68,8 +68,8 @@ except:
print g, "is not an instance" print g, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % g s = "%s" % g
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print g, "is not an ArithUnaryFunction" print g, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError
@ -81,7 +81,7 @@ except:
print h, "is not an instance" print h, "is not an instance"
raise RuntimeError raise RuntimeError
s = '%s' % h s = "%s" % h
if str.find(s, 'ArithUnaryFunction') == -1: if str.find(s, "ArithUnaryFunction") == -1:
print h, "is not an ArithUnaryFunction" print h, "is not an ArithUnaryFunction"
raise RuntimeError raise RuntimeError

View file

@ -5,13 +5,13 @@ import unicode_strings
# The 'u' string prefix isn't valid in Python 3.0 - 3.2 and is redundant # The 'u' string prefix isn't valid in Python 3.0 - 3.2 and is redundant
# in 3.3+. Since this file is run through 2to3 before testing, though, # in 3.3+. Since this file is run through 2to3 before testing, though,
# mark this as a unicode string in 2.x so it'll become a str in 3.x. # mark this as a unicode string in 2.x so it'll become a str in 3.x.
test_string = u'h\udce9llo w\u00f6rld' test_string = u"h\udce9llo w\u00f6rld"
if sys.version_info[0:2] >= (3, 1): if sys.version_info[0:2] >= (3, 1):
if unicode_strings.non_utf8_c_str() != test_string: if unicode_strings.non_utf8_c_str() != test_string:
raise ValueError('Test comparison mismatch') raise ValueError("Test comparison mismatch")
if unicode_strings.non_utf8_std_string() != test_string: if unicode_strings.non_utf8_std_string() != test_string:
raise ValueError('Test comparison mismatch') raise ValueError("Test comparison mismatch")
def check(s1, s2): def check(s1, s2):
if s1 != s2: if s1 != s2:

View file

@ -685,13 +685,13 @@ public:
* same package, otherwise load it as a global module. * same package, otherwise load it as a global module.
*/ */
Printv(default_import_code, "# Import the low-level C/C++ module\n", NULL); Printv(default_import_code, "# Import the low-level C/C++ module\n", NULL);
Printv(default_import_code, "if __package__ or '.' in __name__:\n", NULL); Printv(default_import_code, "if __package__ or \".\" in __name__:\n", NULL);
Printv(default_import_code, tab4, "from . import ", module, "\n", NULL); Printv(default_import_code, tab4, "from . import ", module, "\n", NULL);
Printv(default_import_code, "else:\n", NULL); Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, tab4, "import ", module, "\n", NULL); Printv(default_import_code, tab4, "import ", module, "\n", NULL);
} else { } else {
Printv(default_import_code, "# Pull in all the attributes from the low-level C/C++ module\n", NULL); Printv(default_import_code, "# Pull in all the attributes from the low-level C/C++ module\n", NULL);
Printv(default_import_code, "if __package__ or '.' in __name__:\n", NULL); Printv(default_import_code, "if __package__ or \".\" in __name__:\n", NULL);
Printv(default_import_code, tab4, "from .", module, " import *\n", NULL); Printv(default_import_code, tab4, "from .", module, " import *\n", NULL);
Printv(default_import_code, "else:\n", NULL); Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, tab4, "from ", module, " import *\n", NULL); Printv(default_import_code, tab4, "from ", module, " import *\n", NULL);
@ -848,7 +848,7 @@ public:
Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL); Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL); Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError('Python 2.7 or later required')\n\n", NULL); Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
if (Len(f_shadow_after_begin) > 0) if (Len(f_shadow_after_begin) > 0)
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL); Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
@ -1720,7 +1720,7 @@ public:
} }
// Write the function annotation // Write the function annotation
if (func_annotation) if (func_annotation)
Printf(doc, ": '%s'", type_str); Printf(doc, ": \"%s\"", type_str);
// Write default value // Write default value
if (value && !calling) { if (value && !calling) {
@ -2011,10 +2011,10 @@ public:
// This must have been an octal number. This is the only case we // This must have been an octal number. This is the only case we
// cannot use in Python directly, since Python 2 and 3 use non- // cannot use in Python directly, since Python 2 and 3 use non-
// compatible representations. // compatible representations.
result = NewString(*s == '-' ? "int('-" : "int('"); result = NewString(*s == '-' ? "int(\"-" : "int(\"");
String *octal_string = NewStringWithSize(p, (int) (end - p)); String *octal_string = NewStringWithSize(p, (int) (end - p));
Append(result, octal_string); Append(result, octal_string);
Append(result, "', 8)"); Append(result, "\", 8)");
Delete(octal_string); Delete(octal_string);
return result; return result;
} }
@ -4425,7 +4425,7 @@ public:
Printv(f_shadow, tab4, str, "\n\n", NIL); Printv(f_shadow, tab4, str, "\n\n", NIL);
} }
Printv(f_shadow, tab4, "thisown = property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); Printv(f_shadow, tab4, "thisown = property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc=\"The membership flag\")\n", NIL);
/* Add static attribute */ /* Add static attribute */
if (GetFlag(n, "feature:python:nondynamic")) { if (GetFlag(n, "feature:python:nondynamic")) {
Printv(f_shadow_file, tab4, "__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n", NIL); Printv(f_shadow_file, tab4, "__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n", NIL);

View file

@ -11,9 +11,9 @@ def remove_old_files():
os.remove(file) os.remove(file)
def download(): def download():
repos = subprocess.Popen(['osc', 'repositories'], stdout=subprocess.PIPE) repos = subprocess.Popen(["osc", "repositories"], stdout=subprocess.PIPE)
for line in repos.stdout: for line in repos.stdout:
command = ['osc', 'buildlog', '--last'] + line.split() command = ["osc", "buildlog", "--last"] + line.split()
filename = "-".join(line.split()) + ".log" filename = "-".join(line.split()) + ".log"
print("Downloading logs using: {}".format(" ".join(command))) print("Downloading logs using: {}".format(" ".join(command)))
buildlog = subprocess.Popen(command, stdout=subprocess.PIPE) buildlog = subprocess.Popen(command, stdout=subprocess.PIPE)

View file

@ -23,7 +23,7 @@ def get_cflags(language, std, compiler):
"scilab":"-Werror " + c_common, "scilab":"-Werror " + c_common,
"tcl":"-Werror " + c_common, "tcl":"-Werror " + c_common,
} }
if compiler == 'clang': if compiler == "clang":
cflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile cflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile
if language not in cflags: if language not in cflags:
@ -54,7 +54,7 @@ def get_cxxflags(language, std, compiler):
"scilab":"-Werror " + cxx_common, "scilab":"-Werror " + cxx_common,
"tcl":"-Werror " + cxx_common, "tcl":"-Werror " + cxx_common,
} }
if compiler == 'clang': if compiler == "clang":
cxxflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile cxxflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile
if language not in cxxflags: if language not in cxxflags:
@ -64,12 +64,12 @@ def get_cxxflags(language, std, compiler):
import argparse import argparse
parser = argparse.ArgumentParser(description="Display CFLAGS or CXXFLAGS to use for testing the SWIG examples and test-suite.") parser = argparse.ArgumentParser(description="Display CFLAGS or CXXFLAGS to use for testing the SWIG examples and test-suite.")
parser.add_argument('-l', '--language', required=True, help='set language to show flags for') parser.add_argument("-l", "--language", required=True, help="set language to show flags for")
flags = parser.add_mutually_exclusive_group(required=True) flags = parser.add_mutually_exclusive_group(required=True)
flags.add_argument('-c', '--cflags', action='store_true', default=False, help='show CFLAGS') flags.add_argument("-c", "--cflags", action="store_true", default=False, help="show CFLAGS")
flags.add_argument('-x', '--cxxflags', action='store_true', default=False, help='show CXXFLAGS') flags.add_argument("-x", "--cxxflags", action="store_true", default=False, help="show CXXFLAGS")
parser.add_argument('-s', '--std', required=False, help='language standard flags for the -std= option') parser.add_argument("-s", "--std", required=False, help="language standard flags for the -std= option")
parser.add_argument('-C', '--compiler', required=False, help='compiler used (clang or gcc)') parser.add_argument("-C", "--compiler", required=False, help="compiler used (clang or gcc)")
args = parser.parse_args() args = parser.parse_args()
if args.cflags: if args.cflags: