From 9e03127246f20ddebd68c3392d26d86d4a5853bd Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 25 Jul 2024 22:58:24 +0200 Subject: [PATCH] print() is a function in Python 3 (#98) --- demo/btrfs-snap.py | 3 ++- demo/extern_python_varargs.py | 9 +++++---- demo/fastcsv.py | 3 ++- demo/gmp.py | 7 ++++--- demo/manual2.py | 15 ++++++++------- demo/pwuid.py | 3 ++- demo/pyobj.py | 5 +++-- demo/readdir.py | 7 ++++--- demo/readdir2.py | 7 ++++--- demo/readdir_ctypes.py | 7 ++++--- demo/winclipboard.py | 3 ++- 11 files changed, 40 insertions(+), 29 deletions(-) diff --git a/demo/btrfs-snap.py b/demo/btrfs-snap.py index fceeaa14..8061f83a 100644 --- a/demo/btrfs-snap.py +++ b/demo/btrfs-snap.py @@ -3,6 +3,7 @@ creates a exactly named snapshots and bails out if they exist """ +from __future__ import print_function import argparse import fcntl @@ -47,6 +48,6 @@ try: fcntl.ioctl(target, lib.BTRFS_IOC_SNAP_CREATE_V2, args_buffer) except IOError as e: - print e + print(e) sys.exit(1) diff --git a/demo/extern_python_varargs.py b/demo/extern_python_varargs.py index ee780790..f832d6a3 100644 --- a/demo/extern_python_varargs.py +++ b/demo/extern_python_varargs.py @@ -1,3 +1,4 @@ +from __future__ import print_function import cffi ffi = cffi.FFI() @@ -46,16 +47,16 @@ def f(n, va): x = lib.fetch_int(va) y = lib.fetch_int(va) z = lib.fetch_int(va) - print (x, y, z) + print(x, y, z) elif n == 1: ptr = lib.fetch_ptr(va) - print 'ptr to:', ffi.cast("int *", ptr)[0] + print('ptr to:', ffi.cast("int *", ptr)[0]) elif n == 2: x = lib.fetch_double(va) y = lib.fetch_double(va) - print (x, y) + print(x, y) else: raise AssertionError(n) return 14 -print lib.my_algo(10) +print(lib.my_algo(10)) diff --git a/demo/fastcsv.py b/demo/fastcsv.py index 6b8d0b40..943dd676 100644 --- a/demo/fastcsv.py +++ b/demo/fastcsv.py @@ -1,3 +1,4 @@ +from __future__ import print_function import csv import cffi @@ -263,4 +264,4 @@ def fastcsv_reader(f, dialect_name): with open('/etc/passwd', 'rb') as f: reader = fastcsv_reader(f, 'unixpwd') for row in reader: - print row + print(row) diff --git a/demo/gmp.py b/demo/gmp.py index 44f233cb..4f0857f3 100644 --- a/demo/gmp.py +++ b/demo/gmp.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys # # This is only a demo based on the GMP library. @@ -8,7 +9,7 @@ try: from _gmp_cffi import ffi, lib except ImportError: - print 'run gmp_build first, then make sure the shared object is on sys.path' + print('run gmp_build first, then make sure the shared object is on sys.path') sys.exit(1) # ffi "knows" about the declared variables and functions from the @@ -22,7 +23,7 @@ b = ffi.new("mpz_t") if len(sys.argv) < 3: - print 'call as %s bigint1, bigint2' % sys.argv[0] + print('call as %s bigint1, bigint2' % sys.argv[0]) sys.exit(2) lib.mpz_init_set_str(a, sys.argv[1], 10) # Assume decimal integers @@ -30,4 +31,4 @@ lib.mpz_add(a, a, b) # a=a+b s = lib.mpz_get_str(ffi.NULL, 10, a) -print ffi.string(s) +print(ffi.string(s)) diff --git a/demo/manual2.py b/demo/manual2.py index 2986244a..598fb7ee 100644 --- a/demo/manual2.py +++ b/demo/manual2.py @@ -1,3 +1,4 @@ +from __future__ import print_function import _cffi_backend ffi = _cffi_backend.FFI(b"manual2", @@ -19,16 +20,16 @@ x = lib.close(-42) assert x == -1 -print lib.stdout +print(lib.stdout) -print ffi.new("struct point_s *") -print ffi.offsetof("struct point_s", "x") -print ffi.offsetof("struct point_s", "y") -print ffi.new("struct point_s[CC]") +print(ffi.new("struct point_s *")) +print(ffi.offsetof("struct point_s", "x")) +print(ffi.offsetof("struct point_s", "y")) +print(ffi.new("struct point_s[CC]")) assert ffi.sizeof("struct point_s[CC]") == 2 * ffi.sizeof("struct point_s") -print ffi.cast("enum myenum_e", 2) -print ffi.cast("myint_t", -2) +print(ffi.cast("enum myenum_e", 2)) +print(ffi.cast("myint_t", -2)) assert ffi.typeof("myint_t") == ffi.typeof("int") del ffi, lib diff --git a/demo/pwuid.py b/demo/pwuid.py index dda92990..7651e6e0 100644 --- a/demo/pwuid.py +++ b/demo/pwuid.py @@ -1,7 +1,8 @@ +from __future__ import print_function import sys, os # run pwuid_build first, then make sure the shared object is on sys.path from _pwuid_cffi import ffi, lib -print ffi.string(lib.getpwuid(0).pw_name) +print(ffi.string(lib.getpwuid(0).pw_name)) diff --git a/demo/pyobj.py b/demo/pyobj.py index b40343a1..922f6da6 100644 --- a/demo/pyobj.py +++ b/demo/pyobj.py @@ -1,3 +1,4 @@ +from __future__ import print_function referents = [] # list "object descriptor -> python object" freelist = None @@ -116,9 +117,9 @@ def pyobj_add(p1, p2): """) with Ref([10, 20, 30, 40]) as p_list: - print lib.sum_integers(p_list) + print(lib.sum_integers(p_list)) with Ref(5) as p_initial: result = discard(lib.sum_objects(p_list, p_initial)) - print result + print(result) assert count_pyobj_alive() == 0 diff --git a/demo/readdir.py b/demo/readdir.py index b9662469..cac9200a 100644 --- a/demo/readdir.py +++ b/demo/readdir.py @@ -1,3 +1,4 @@ +from __future__ import print_function # A Linux-only demo # import sys @@ -10,7 +11,7 @@ def walk(basefd, path): - print '{', path + print('{', path) dirfd = lib.openat(basefd, path, 0) if dirfd < 0: # error in openat() @@ -25,11 +26,11 @@ def walk(basefd, path): if result[0] == ffi.NULL: break name = ffi.string(dirent.d_name) - print '%3d %s' % (dirent.d_type, name) + print('%3d %s' % (dirent.d_type, name)) if dirent.d_type == 4 and name != '.' and name != '..': walk(dirfd, name) lib.closedir(dir) - print '}' + print('}') walk(-1, "/tmp") diff --git a/demo/readdir2.py b/demo/readdir2.py index b564b514..601cd2ce 100644 --- a/demo/readdir2.py +++ b/demo/readdir2.py @@ -1,3 +1,4 @@ +from __future__ import print_function # A Linux-only demo, using set_source() instead of hard-coding the exact layouts # import sys @@ -10,7 +11,7 @@ def walk(basefd, path): - print '{', path + print('{', path) dirfd = lib.openat(basefd, path, 0) if dirfd < 0: # error in openat() @@ -25,11 +26,11 @@ def walk(basefd, path): if result[0] == ffi.NULL: break name = ffi.string(dirent.d_name) - print '%3d %s' % (dirent.d_type, name) + print('%3d %s' % (dirent.d_type, name)) if dirent.d_type == lib.DT_DIR and name != '.' and name != '..': walk(dirfd, name) lib.closedir(dir) - print '}' + print('}') walk(-1, "/tmp") diff --git a/demo/readdir_ctypes.py b/demo/readdir_ctypes.py index 4fd1d176..8f7f14db 100644 --- a/demo/readdir_ctypes.py +++ b/demo/readdir_ctypes.py @@ -1,3 +1,4 @@ +from __future__ import print_function # A Linux-only demo # # For comparison purposes, this is a ctypes version of readdir.py. @@ -44,7 +45,7 @@ class DIRENT(ctypes.Structure): def walk(basefd, path): - print '{', path + print('{', path) dirfd = openat(basefd, path, 0) if dirfd < 0: # error in openat() @@ -59,11 +60,11 @@ def walk(basefd, path): if not result: break name = dirent.d_name - print '%3d %s' % (dirent.d_type, name) + print('%3d %s' % (dirent.d_type, name)) if dirent.d_type == 4 and name != '.' and name != '..': walk(dirfd, name) closedir(dir) - print '}' + print('}') walk(-1, "/tmp") diff --git a/demo/winclipboard.py b/demo/winclipboard.py index 5278cd0b..e7335e45 100644 --- a/demo/winclipboard.py +++ b/demo/winclipboard.py @@ -1,3 +1,4 @@ +from __future__ import print_function __author__ = "Israel Fruchter " import sys, os @@ -8,7 +9,7 @@ try: from _winclipboard_cffi import ffi, lib except ImportError: - print 'run winclipboard_build first, then make sure the shared object is on sys.path' + print('run winclipboard_build first, then make sure the shared object is on sys.path') sys.exit(1) # ffi "knows" about the declared variables and functions from the