Skip to content

Commit

Permalink
print() is a function in Python 3 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Jul 25, 2024
1 parent c739b59 commit 9e03127
Showing 11 changed files with 40 additions and 29 deletions.
3 changes: 2 additions & 1 deletion demo/btrfs-snap.py
Original file line number Diff line number Diff line change
@@ -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)

9 changes: 5 additions & 4 deletions demo/extern_python_varargs.py
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion demo/fastcsv.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions demo/gmp.py
Original file line number Diff line number Diff line change
@@ -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,12 +23,12 @@
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
lib.mpz_init_set_str(b, sys.argv[2], 10) # Assume decimal integers
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))
15 changes: 8 additions & 7 deletions demo/manual2.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion demo/pwuid.py
Original file line number Diff line number Diff line change
@@ -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))
5 changes: 3 additions & 2 deletions demo/pyobj.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions demo/readdir.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 4 additions & 3 deletions demo/readdir2.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 4 additions & 3 deletions demo/readdir_ctypes.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion demo/winclipboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
__author__ = "Israel Fruchter <[email protected]>"

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

0 comments on commit 9e03127

Please sign in to comment.