Python3: use print function
Florent Viard authored on 2016/09/09 23:53:47... | ... |
@@ -6,6 +6,8 @@ |
6 | 6 |
## License: GPL Version 2 |
7 | 7 |
## Copyright: TGRMN Software and contributors |
8 | 8 |
|
9 |
+from __future__ import print_function |
|
10 |
+ |
|
9 | 11 |
from Utils import getTreeFromXml, deunicodise |
10 | 12 |
|
11 | 13 |
try: |
... | ... |
@@ -222,11 +224,11 @@ if __name__ == "__main__": |
222 | 222 |
</AccessControlPolicy> |
223 | 223 |
""" |
224 | 224 |
acl = ACL(xml) |
225 |
- print "Grants:", acl.getGrantList() |
|
225 |
+ print("Grants:", acl.getGrantList()) |
|
226 | 226 |
acl.revokeAnonRead() |
227 |
- print "Grants:", acl.getGrantList() |
|
227 |
+ print("Grants:", acl.getGrantList()) |
|
228 | 228 |
acl.grantAnonRead() |
229 |
- print "Grants:", acl.getGrantList() |
|
230 |
- print acl |
|
229 |
+ print("Grants:", acl.getGrantList()) |
|
230 |
+ print(acl) |
|
231 | 231 |
|
232 | 232 |
# vim:et:ts=4:sts=4:ai |
... | ... |
@@ -6,6 +6,8 @@ |
6 | 6 |
## License: GPL Version 2 |
7 | 7 |
## Copyright: TGRMN Software and contributors |
8 | 8 |
|
9 |
+from __future__ import print_function |
|
10 |
+ |
|
9 | 11 |
import S3Uri |
10 | 12 |
from Exceptions import ParameterError |
11 | 13 |
from Utils import getTreeFromXml |
... | ... |
@@ -80,14 +82,14 @@ __all__.append("AccessLog") |
80 | 80 |
|
81 | 81 |
if __name__ == "__main__": |
82 | 82 |
log = AccessLog() |
83 |
- print log |
|
83 |
+ print(log) |
|
84 | 84 |
log.enableLogging(S3Uri.S3Uri(u"s3://targetbucket/prefix/log-")) |
85 |
- print log |
|
85 |
+ print(log) |
|
86 | 86 |
log.setAclPublic(True) |
87 |
- print log |
|
87 |
+ print(log) |
|
88 | 88 |
log.setAclPublic(False) |
89 |
- print log |
|
89 |
+ print(log) |
|
90 | 90 |
log.disableLogging() |
91 |
- print log |
|
91 |
+ print(log) |
|
92 | 92 |
|
93 | 93 |
# vim:et:ts=4:sts=4:ai |
... | ... |
@@ -6,6 +6,8 @@ |
6 | 6 |
## License: GPL Version 2 |
7 | 7 |
## Copyright: TGRMN Software and contributors |
8 | 8 |
|
9 |
+from __future__ import print_function |
|
10 |
+ |
|
9 | 11 |
import os |
10 | 12 |
import re |
11 | 13 |
import sys |
... | ... |
@@ -185,39 +187,39 @@ class S3UriCloudFront(S3Uri): |
185 | 185 |
|
186 | 186 |
if __name__ == "__main__": |
187 | 187 |
uri = S3Uri("s3://bucket/object") |
188 |
- print "type() =", type(uri) |
|
189 |
- print "uri =", uri |
|
190 |
- print "uri.type=", uri.type |
|
191 |
- print "bucket =", uri.bucket() |
|
192 |
- print "object =", uri.object() |
|
193 |
|
|
188 |
+ print("type() =", type(uri)) |
|
189 |
+ print("uri =", uri) |
|
190 |
+ print("uri.type=", uri.type) |
|
191 |
+ print("bucket =", uri.bucket()) |
|
192 |
+ print("object =", uri.object()) |
|
193 |
+ print() |
|
194 | 194 |
|
195 | 195 |
uri = S3Uri("s3://bucket") |
196 |
- print "type() =", type(uri) |
|
197 |
- print "uri =", uri |
|
198 |
- print "uri.type=", uri.type |
|
199 |
- print "bucket =", uri.bucket() |
|
200 |
|
|
196 |
+ print("type() =", type(uri)) |
|
197 |
+ print("uri =", uri) |
|
198 |
+ print("uri.type=", uri.type) |
|
199 |
+ print("bucket =", uri.bucket()) |
|
200 |
+ print() |
|
201 | 201 |
|
202 | 202 |
uri = S3Uri("s3fs://filesystem1/path/to/remote/file.txt") |
203 |
- print "type() =", type(uri) |
|
204 |
- print "uri =", uri |
|
205 |
- print "uri.type=", uri.type |
|
206 |
- print "path =", uri.path() |
|
207 |
|
|
203 |
+ print("type() =", type(uri)) |
|
204 |
+ print("uri =", uri) |
|
205 |
+ print("uri.type=", uri.type) |
|
206 |
+ print("path =", uri.path()) |
|
207 |
+ print() |
|
208 | 208 |
|
209 | 209 |
uri = S3Uri("/path/to/local/file.txt") |
210 |
- print "type() =", type(uri) |
|
211 |
- print "uri =", uri |
|
212 |
- print "uri.type=", uri.type |
|
213 |
- print "path =", uri.path() |
|
214 |
|
|
210 |
+ print("type() =", type(uri)) |
|
211 |
+ print("uri =", uri) |
|
212 |
+ print("uri.type=", uri.type) |
|
213 |
+ print("path =", uri.path()) |
|
214 |
+ print() |
|
215 | 215 |
|
216 | 216 |
uri = S3Uri("cf://1234567890ABCD/") |
217 |
- print "type() =", type(uri) |
|
218 |
- print "uri =", uri |
|
219 |
- print "uri.type=", uri.type |
|
220 |
- print "dist_id =", uri.dist_id() |
|
221 |
|
|
217 |
+ print("type() =", type(uri)) |
|
218 |
+ print("uri =", uri) |
|
219 |
+ print("uri.type=", uri.type) |
|
220 |
+ print("dist_id =", uri.dist_id()) |
|
221 |
+ print() |
|
222 | 222 |
|
223 | 223 |
# vim:et:ts=4:sts=4:ai |
... | ... |
@@ -6,6 +6,8 @@ |
6 | 6 |
## License: GPL Version 2 |
7 | 7 |
## Copyright: TGRMN Software and contributors |
8 | 8 |
|
9 |
+from __future__ import print_function |
|
10 |
+ |
|
9 | 11 |
from BidirMap import BidirMap |
10 | 12 |
|
11 | 13 |
class SortedDictIterator(object): |
... | ... |
@@ -59,16 +61,16 @@ class SortedDict(dict): |
59 | 59 |
if __name__ == "__main__": |
60 | 60 |
d = { 'AWS' : 1, 'Action' : 2, 'america' : 3, 'Auckland' : 4, 'America' : 5 } |
61 | 61 |
sd = SortedDict(d) |
62 |
- print "Wanted: Action, america, Auckland, AWS, [ignore case]" |
|
63 |
- print "Got: ", |
|
62 |
+ print("Wanted: Action, america, Auckland, AWS, [ignore case]") |
|
63 |
+ print("Got: ", end=' ') |
|
64 | 64 |
for key in sd: |
65 |
- print "%s," % key, |
|
66 |
- print " [used: __iter__()]" |
|
65 |
+ print("%s," % key, end=' ') |
|
66 |
+ print(" [used: __iter__()]") |
|
67 | 67 |
d = SortedDict(d, ignore_case = False) |
68 |
- print "Wanted: AWS, Action, Auckland, america, [case sensitive]" |
|
69 |
- print "Got: ", |
|
68 |
+ print("Wanted: AWS, Action, Auckland, america, [case sensitive]") |
|
69 |
+ print("Got: ", end=' ') |
|
70 | 70 |
for key in d.keys(): |
71 |
- print "%s," % key, |
|
72 |
- print " [used: keys()]" |
|
71 |
+ print("%s," % key, end=' ') |
|
72 |
+ print(" [used: keys()]") |
|
73 | 73 |
|
74 | 74 |
# vim:et:ts=4:sts=4:ai |
... | ... |
@@ -7,6 +7,8 @@ |
7 | 7 |
## License: GPL Version 2 |
8 | 8 |
## Copyright: TGRMN Software and contributors |
9 | 9 |
|
10 |
+from __future__ import print_function |
|
11 |
+ |
|
10 | 12 |
import sys |
11 | 13 |
import os |
12 | 14 |
import re |
... | ... |
@@ -62,12 +64,12 @@ elif os.name == "nt" and os.getenv("USERPROFILE"): |
62 | 62 |
if not os.path.isdir('testsuite') and os.path.isfile('testsuite.tar.gz'): |
63 | 63 |
os.system("tar -xz -f testsuite.tar.gz") |
64 | 64 |
if not os.path.isdir('testsuite'): |
65 |
- print "Something went wrong while unpacking testsuite.tar.gz" |
|
65 |
+ print("Something went wrong while unpacking testsuite.tar.gz") |
|
66 | 66 |
sys.exit(1) |
67 | 67 |
|
68 | 68 |
os.system("tar -xf testsuite/checksum.tar -C testsuite") |
69 | 69 |
if not os.path.isfile('testsuite/checksum/cksum33.txt'): |
70 |
- print "Something went wrong while unpacking testsuite/checkum.tar" |
|
70 |
+ print("Something went wrong while unpacking testsuite/checkum.tar") |
|
71 | 71 |
sys.exit(1) |
72 | 72 |
|
73 | 73 |
## Fix up permissions for permission-denied tests |
... | ... |
@@ -81,10 +83,10 @@ patterns['GBK'] = u"12月31日/1-特色條目" |
81 | 81 |
|
82 | 82 |
encoding = locale.getpreferredencoding() |
83 | 83 |
if not encoding: |
84 |
- print "Guessing current system encoding failed. Consider setting $LANG variable." |
|
84 |
+ print("Guessing current system encoding failed. Consider setting $LANG variable.") |
|
85 | 85 |
sys.exit(1) |
86 | 86 |
else: |
87 |
- print "System encoding: " + encoding |
|
87 |
+ print("System encoding: " + encoding) |
|
88 | 88 |
|
89 | 89 |
have_encoding = os.path.isdir('testsuite/encodings/' + encoding) |
90 | 90 |
if not have_encoding and os.path.isfile('testsuite/encodings/%s.tar.gz' % encoding): |
... | ... |
@@ -95,7 +97,7 @@ if have_encoding: |
95 | 95 |
#enc_base_remote = "%s/xyz/%s/" % (pbucket(1), encoding) |
96 | 96 |
enc_pattern = patterns[encoding] |
97 | 97 |
else: |
98 |
- print encoding + " specific files not found." |
|
98 |
+ print(encoding + " specific files not found.") |
|
99 | 99 |
|
100 | 100 |
if not os.path.isdir('testsuite/crappy-file-name'): |
101 | 101 |
os.system("tar xvz -C testsuite -f testsuite/crappy-file-name.tar.gz") |
... | ... |
@@ -104,17 +106,17 @@ if not os.path.isdir('testsuite/crappy-file-name'): |
104 | 104 |
|
105 | 105 |
def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = [], stdin = None): |
106 | 106 |
def command_output(): |
107 |
- print "----" |
|
108 |
- print " ".join([" " in arg and "'%s'" % arg or arg for arg in cmd_args]) |
|
109 |
- print "----" |
|
110 |
- print stdout |
|
111 |
- print "----" |
|
107 |
+ print("----") |
|
108 |
+ print(" ".join([" " in arg and "'%s'" % arg or arg for arg in cmd_args])) |
|
109 |
+ print("----") |
|
110 |
+ print(stdout) |
|
111 |
+ print("----") |
|
112 | 112 |
|
113 | 113 |
def failure(message = ""): |
114 | 114 |
global count_fail |
115 | 115 |
if message: |
116 | 116 |
message = u" (%r)" % message |
117 |
- print u"\x1b[31;1mFAIL%s\x1b[0m" % (message) |
|
117 |
+ print(u"\x1b[31;1mFAIL%s\x1b[0m" % (message)) |
|
118 | 118 |
count_fail += 1 |
119 | 119 |
command_output() |
120 | 120 |
#return 1 |
... | ... |
@@ -123,7 +125,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
123 | 123 |
global count_pass |
124 | 124 |
if message: |
125 | 125 |
message = " (%r)" % message |
126 |
- print "\x1b[32;1mOK\x1b[0m%s" % (message) |
|
126 |
+ print("\x1b[32;1mOK\x1b[0m%s" % (message)) |
|
127 | 127 |
count_pass += 1 |
128 | 128 |
if verbose: |
129 | 129 |
command_output() |
... | ... |
@@ -132,7 +134,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
132 | 132 |
global count_skip |
133 | 133 |
if message: |
134 | 134 |
message = " (%r)" % message |
135 |
- print "\x1b[33;1mSKIP\x1b[0m%s" % (message) |
|
135 |
+ print("\x1b[33;1mSKIP\x1b[0m%s" % (message)) |
|
136 | 136 |
count_skip += 1 |
137 | 137 |
return 0 |
138 | 138 |
def compile_list(_list, regexps = False): |
... | ... |
@@ -143,7 +145,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
143 | 143 |
|
144 | 144 |
global test_counter |
145 | 145 |
test_counter += 1 |
146 |
- print ("%3d %s " % (test_counter, label)).ljust(30, "."), |
|
146 |
+ print(("%3d %s " % (test_counter, label)).ljust(30, "."), end=' ') |
|
147 | 147 |
sys.stdout.flush() |
148 | 148 |
|
149 | 149 |
if run_tests.count(test_counter) == 0 or exclude_tests.count(test_counter) > 0: |
... | ... |
@@ -202,7 +204,7 @@ def test_mkdir(label, dir_name): |
202 | 202 |
if os.name in ("posix", "nt"): |
203 | 203 |
cmd = ['mkdir', '-p'] |
204 | 204 |
else: |
205 |
- print "Unknown platform: %s" % os.name |
|
205 |
+ print("Unknown platform: %s" % os.name) |
|
206 | 206 |
sys.exit(1) |
207 | 207 |
cmd.append(dir_name) |
208 | 208 |
return test(label, cmd) |
... | ... |
@@ -214,7 +216,7 @@ def test_rmdir(label, dir_name): |
214 | 214 |
elif os.name == "nt": |
215 | 215 |
cmd = ['rmdir', '/s/q'] |
216 | 216 |
else: |
217 |
- print "Unknown platform: %s" % os.name |
|
217 |
+ print("Unknown platform: %s" % os.name) |
|
218 | 218 |
sys.exit(1) |
219 | 219 |
cmd.append(dir_name) |
220 | 220 |
return test(label, cmd) |
... | ... |
@@ -231,7 +233,7 @@ def test_copy(label, src_file, dst_file): |
231 | 231 |
elif os.name == "nt": |
232 | 232 |
cmd = ['copy'] |
233 | 233 |
else: |
234 |
- print "Unknown platform: %s" % os.name |
|
234 |
+ print("Unknown platform: %s" % os.name) |
|
235 | 235 |
sys.exit(1) |
236 | 236 |
cmd.append(src_file) |
237 | 237 |
cmd.append(dst_file) |
... | ... |
@@ -248,11 +250,11 @@ argv = sys.argv[1:] |
248 | 248 |
while argv: |
249 | 249 |
arg = argv.pop(0) |
250 | 250 |
if arg.startswith('--bucket-prefix='): |
251 |
- print "Usage: '--bucket-prefix PREFIX', not '--bucket-prefix=PREFIX'" |
|
251 |
+ print("Usage: '--bucket-prefix PREFIX', not '--bucket-prefix=PREFIX'") |
|
252 | 252 |
sys.exit(0) |
253 | 253 |
if arg in ("-h", "--help"): |
254 |
- print "%s A B K..O -N" % sys.argv[0] |
|
255 |
- print "Run tests number A, B and K through to O, except for N" |
|
254 |
+ print("%s A B K..O -N" % sys.argv[0]) |
|
255 |
+ print("Run tests number A, B and K through to O, except for N") |
|
256 | 256 |
sys.exit(0) |
257 | 257 |
|
258 | 258 |
if arg in ("-c", "--config"): |
... | ... |
@@ -268,7 +270,7 @@ while argv: |
268 | 268 |
try: |
269 | 269 |
bucket_prefix = argv.pop(0) |
270 | 270 |
except IndexError: |
271 |
- print "Bucket prefix option must explicitly supply a bucket name prefix" |
|
271 |
+ print("Bucket prefix option must explicitly supply a bucket name prefix") |
|
272 | 272 |
sys.exit(0) |
273 | 273 |
continue |
274 | 274 |
if ".." in arg: |
... | ... |
@@ -281,7 +283,7 @@ while argv: |
281 | 281 |
else: |
282 | 282 |
run_tests.append(int(arg)) |
283 | 283 |
|
284 |
-print "Using bucket prefix: '%s'" % bucket_prefix |
|
284 |
+print("Using bucket prefix: '%s'" % bucket_prefix) |
|
285 | 285 |
|
286 | 286 |
cfg = S3.Config.Config(config_file) |
287 | 287 |
|
... | ... |
@@ -1,17 +1,19 @@ |
1 | 1 |
#!/usr/bin/env python2 |
2 | 2 |
# -*- coding=utf-8 -*- |
3 | 3 |
|
4 |
+from __future__ import print_function |
|
5 |
+ |
|
4 | 6 |
import sys |
5 | 7 |
import os |
6 | 8 |
|
7 | 9 |
try: |
8 | 10 |
import xml.etree.ElementTree |
9 |
- print "Using xml.etree.ElementTree for XML processing" |
|
11 |
+ print("Using xml.etree.ElementTree for XML processing") |
|
10 | 12 |
except ImportError, e: |
11 | 13 |
sys.stderr.write(str(e) + "\n") |
12 | 14 |
try: |
13 | 15 |
import elementtree.ElementTree |
14 |
- print "Using elementtree.ElementTree for XML processing" |
|
16 |
+ print("Using elementtree.ElementTree for XML processing") |
|
15 | 17 |
except ImportError, e: |
16 | 18 |
sys.stderr.write(str(e) + "\n") |
17 | 19 |
sys.stderr.write("Please install ElementTree module from\n") |