Skip to content

Commit 16cfffd

Browse files
committed
Few changes
1 parent eff9108 commit 16cfffd

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

examples/test_examples.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def test_minimal_working_example(self):
4242
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"))
4343
session = driver.session()
4444

45-
session.run("CREATE (neo:Person {name:'Neo', age:23})")
45+
session.run("CREATE (a:Person {name:'Arthur', title:'King'})", )
4646

47-
result = session.run("MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age")
47+
result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title")
4848
while result.next():
49-
print("Neo is %d years old." % result["p.age"])
49+
print("%s %s" % (result["title"], result["name"]))
5050

5151
session.close()
5252
# end::minimal-example[]

neo4j/v1/compat.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,39 @@
3232
try:
3333
unicode
3434
except NameError:
35+
# Python 3
36+
3537
integer = int
3638
string = str
3739

40+
def ustr(x):
41+
if isinstance(x, bytes):
42+
return x.decode("utf-8")
43+
elif isinstance(x, str):
44+
return x
45+
else:
46+
return str(x)
47+
3848
def hex2(x):
3949
if x < 0x10:
4050
return "0" + hex(x)[2:].upper()
4151
else:
4252
return hex(x)[2:].upper()
4353

4454
else:
55+
# Python 2
56+
4557
integer = (int, long)
4658
string = (str, unicode)
4759

60+
def ustr(x):
61+
if isinstance(x, str):
62+
return x.decode("utf-8")
63+
elif isinstance(x, unicode):
64+
return x
65+
else:
66+
return unicode(x)
67+
4868
def hex2(x):
4969
x = ord(x)
5070
if x < 0x10:

0 commit comments

Comments
 (0)