Mercurial > cpython-lru_cache-weakref
diff Doc/includes/sqlite3/text_factory.py @ 75360:d2cf730de195 2.7
sqlite3: Port relevant documentation changes from 3.2
Initial patch by Johannes Vogel. Issue #13491.
| author | Petri Lehtinen <petri@digip.org> |
|---|---|
| date | Thu, 01 Mar 2012 21:28:00 +0200 |
| parents | 3e15a07a32fa |
| children |
line wrap: on
line diff
--- a/Doc/includes/sqlite3/text_factory.py Thu Mar 01 16:26:35 2012 +0100 +++ b/Doc/includes/sqlite3/text_factory.py Thu Mar 01 21:28:00 2012 +0200 @@ -3,9 +3,6 @@ con = sqlite3.connect(":memory:") cur = con.cursor() -# Create the table -con.execute("create table person(lastname, firstname)") - AUSTRIA = u"\xd6sterreich" # by default, rows are returned as Unicode @@ -17,7 +14,7 @@ con.text_factory = str cur.execute("select ?", (AUSTRIA,)) row = cur.fetchone() -assert type(row[0]) == str +assert type(row[0]) is str # the bytestrings will be encoded in UTF-8, unless you stored garbage in the # database ... assert row[0] == AUSTRIA.encode("utf-8") @@ -29,15 +26,15 @@ cur.execute("select ?", ("this is latin1 and would normally create errors" + u"\xe4\xf6\xfc".encode("latin1"),)) row = cur.fetchone() -assert type(row[0]) == unicode +assert type(row[0]) is unicode # sqlite3 offers a built-in optimized text_factory that will return bytestring # objects, if the data is in ASCII only, and otherwise return unicode objects con.text_factory = sqlite3.OptimizedUnicode cur.execute("select ?", (AUSTRIA,)) row = cur.fetchone() -assert type(row[0]) == unicode +assert type(row[0]) is unicode cur.execute("select ?", ("Germany",)) row = cur.fetchone() -assert type(row[0]) == str +assert type(row[0]) is str
