summaryrefslogtreecommitdiff
path: root/examples/encoding.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/encoding.py')
-rw-r--r--examples/encoding.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/examples/encoding.py b/examples/encoding.py
index 77fd871..693a88d 100644
--- a/examples/encoding.py
+++ b/examples/encoding.py
@@ -26,80 +26,80 @@ import psycopg2.extensions
if len(sys.argv) > 1:
DSN = sys.argv[1]
-print "Opening connection using dsn:", DSN
+print("Opening connection using dsn:", DSN)
conn = psycopg2.connect(DSN)
-print "Initial encoding for this connection is", conn.encoding
+print("Initial encoding for this connection is", conn.encoding)
-print "\n** This example is supposed to be run in a UNICODE terminal! **\n"
+print("\n** This example is supposed to be run in a UNICODE terminal! **\n")
-print "Available encodings:"
+print("Available encodings:")
encs = psycopg2.extensions.encodings.items()
encs.sort()
for a, b in encs:
- print " ", a, "<->", b
+ print(" ", a, "<->", b)
-print "Using STRING typecaster"
-print "Setting backend encoding to LATIN1 and executing queries:"
+print("Using STRING typecaster")
+print("Setting backend encoding to LATIN1 and executing queries:")
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
-print " ->", unicode(x, 'latin-1').encode('utf-8'), type(x)
+print(" ->", unicode(x, 'latin-1').encode('utf-8'), type(x))
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", unicode(x, 'latin-1').encode('utf-8'), type(x)
+print(" ->", unicode(x, 'latin-1').encode('utf-8'), type(x))
-print "Setting backend encoding to UTF8 and executing queries:"
+print("Setting backend encoding to UTF8 and executing queries:")
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
-print " ->", x, type(x)
+print(" ->", x, type(x))
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", x, type(x)
+print(" ->", x, type(x))
-print "Using UNICODE typecaster"
+print("Using UNICODE typecaster")
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
-print "Setting backend encoding to LATIN1 and executing queries:"
+print("Setting backend encoding to LATIN1 and executing queries:")
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
-print "Setting backend encoding to UTF8 and executing queries:"
+print("Setting backend encoding to UTF8 and executing queries:")
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
-print "Executing full UNICODE queries"
+print("Executing full UNICODE queries")
-print "Setting backend encoding to LATIN1 and executing queries:"
+print("Setting backend encoding to LATIN1 and executing queries:")
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute(u"SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
-print "Setting backend encoding to UTF8 and executing queries:"
+print("Setting backend encoding to UTF8 and executing queries:")
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
-print " ->", x.encode('utf-8'), ":", type(x)
+print(" ->", x.encode('utf-8'), ":", type(x))