Skip to content

Commit 30979c6

Browse files
Modify samples to follow the PEP 8 style guide.
1 parent 6b9a7b0 commit 30979c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+389
-396
lines changed

doc/src/release_notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Version 8.1 (TBD)
2626
#) Tests can now be run with tox in order to automate testing of the different
2727
environments that are supported.
2828
#) The value of prefetchrows for REF CURSOR variables is now honored.
29-
#) Improved documentation and test suite.
29+
#) Improved documentation, samples and test suite.
3030

3131

3232
Version 8.0.1 (August 2020)

samples/AdvancedQueuingNotification.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
#------------------------------------------------------------------------------
44

55
#------------------------------------------------------------------------------
@@ -13,7 +13,7 @@
1313
#------------------------------------------------------------------------------
1414

1515
import cx_Oracle
16-
import SampleEnv
16+
import sample_env
1717
import threading
1818
import time
1919

@@ -29,9 +29,11 @@ def ProcessMessages(message):
2929
print("Queue name:", message.queueName)
3030
print("Consumer name:", message.consumerName)
3131

32-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString(), events = True)
32+
connection = cx_Oracle.connect(sample_env.get_main_connect_string(),
33+
events=True)
3334
sub = connection.subscribe(namespace=cx_Oracle.SUBSCR_NAMESPACE_AQ,
34-
name="DEMO_BOOK_QUEUE", callback=ProcessMessages, timeout=300)
35+
name="DEMO_BOOK_QUEUE", callback=ProcessMessages,
36+
timeout=300)
3537
print("Subscription:", sub)
3638
print("--> Connection:", sub.connection)
3739
print("--> Callback:", sub.callback)

samples/AppContext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#
44
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
55
#
@@ -17,7 +17,7 @@
1717
#------------------------------------------------------------------------------
1818

1919
import cx_Oracle
20-
import SampleEnv
20+
import sample_env
2121

2222
# define constants used throughout the script; adjust as desired
2323
APP_CTX_NAMESPACE = "CLIENTCONTEXT"
@@ -27,8 +27,8 @@
2727
( APP_CTX_NAMESPACE, "ATTR3", "VALUE3" )
2828
]
2929

30-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString(),
31-
appcontext = APP_CTX_ENTRIES)
30+
connection = cx_Oracle.connect(sample_env.get_main_connect_string(),
31+
appcontext=APP_CTX_ENTRIES)
3232
cursor = connection.cursor()
3333
for namespace, name, value in APP_CTX_ENTRIES:
3434
cursor.execute("select sys_context(:1, :2) from dual", (namespace, name))

samples/ArrayDMLRowCounts.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#------------------------------------------------------------------------------
44

55
#------------------------------------------------------------------------------
@@ -14,36 +14,36 @@
1414
#------------------------------------------------------------------------------
1515

1616
import cx_Oracle
17-
import SampleEnv
17+
import sample_env
1818

19-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
19+
connection = cx_Oracle.connect(sample_env.get_main_connect_string())
2020
cursor = connection.cursor()
2121

2222
# show the number of rows for each parent ID as a means of verifying the
2323
# output from the delete statement
24-
for parentId, count in cursor.execute("""
24+
for parent_id, count in cursor.execute("""
2525
select ParentId, count(*)
2626
from ChildTable
2727
group by ParentId
2828
order by ParentId"""):
29-
print("Parent ID:", parentId, "has", int(count), "rows.")
29+
print("Parent ID:", parent_id, "has", int(count), "rows.")
3030
print()
3131

3232
# delete the following parent IDs only
33-
parentIdsToDelete = [20, 30, 50]
33+
parent_ids_to_delete = [20, 30, 50]
3434

35-
print("Deleting Parent IDs:", parentIdsToDelete)
35+
print("Deleting Parent IDs:", parent_ids_to_delete)
3636
print()
3737

3838
# enable array DML row counts for each iteration executed in executemany()
3939
cursor.executemany("""
4040
delete from ChildTable
4141
where ParentId = :1""",
42-
[(i,) for i in parentIdsToDelete],
42+
[(i,) for i in parent_ids_to_delete],
4343
arraydmlrowcounts = True)
4444

4545
# display the number of rows deleted for each parent ID
46-
rowCounts = cursor.getarraydmlrowcounts()
47-
for parentId, count in zip(parentIdsToDelete, rowCounts):
48-
print("Parent ID:", parentId, "deleted", count, "rows.")
46+
row_counts = cursor.getarraydmlrowcounts()
47+
for parent_id, count in zip(parent_ids_to_delete, row_counts):
48+
print("Parent ID:", parent_id, "deleted", count, "rows.")
4949

samples/BatchErrors.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#------------------------------------------------------------------------------
44

55
#------------------------------------------------------------------------------
@@ -16,13 +16,13 @@
1616
#------------------------------------------------------------------------------
1717

1818
import cx_Oracle
19-
import SampleEnv
19+
import sample_env
2020

21-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
21+
connection = cx_Oracle.connect(sample_env.get_main_connect_string())
2222
cursor = connection.cursor()
2323

2424
# define data to insert
25-
dataToInsert = [
25+
data_to_insert = [
2626
(1016, 10, 'Child B of Parent 10'),
2727
(1017, 10, 'Child C of Parent 10'),
2828
(1018, 20, 'Child D of Parent 20'),
@@ -39,14 +39,14 @@
3939
from ChildTable""")
4040
count, = cursor.fetchone()
4141
print("number of rows in child table:", int(count))
42-
print("number of rows to insert:", len(dataToInsert))
42+
print("number of rows to insert:", len(data_to_insert))
4343

4444
# old method: executemany() with data errors results in stoppage after the
4545
# first error takes place; the row count is updated to show how many rows
4646
# actually succeeded
4747
try:
4848
cursor.executemany("insert into ChildTable values (:1, :2, :3)",
49-
dataToInsert)
49+
data_to_insert)
5050
except cx_Oracle.DatabaseError as e:
5151
error, = e.args
5252
print("FAILED with error:", error.message)
@@ -64,12 +64,12 @@
6464

6565
# new method: executemany() with batch errors enabled (and array DML row counts
6666
# also enabled) results in no immediate error being raised
67-
cursor.executemany("insert into ChildTable values (:1, :2, :3)", dataToInsert,
68-
batcherrors = True, arraydmlrowcounts = True)
67+
cursor.executemany("insert into ChildTable values (:1, :2, :3)",
68+
data_to_insert, batcherrors=True, arraydmlrowcounts=True)
6969

7070
# where errors have taken place, the row count is 0; otherwise it is 1
71-
rowCounts = cursor.getarraydmlrowcounts()
72-
print("Array DML row counts:", rowCounts)
71+
row_counts = cursor.getarraydmlrowcounts()
72+
print("Array DML row counts:", row_counts)
7373

7474
# display the errors that have taken place
7575
errors = cursor.getbatcherrors()

samples/BindInsert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#------------------------------------------------------------------------------
44

55
#------------------------------------------------------------------------------
@@ -9,9 +9,9 @@
99
#------------------------------------------------------------------------------
1010

1111
import cx_Oracle
12-
import SampleEnv
12+
import sample_env
1313

14-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
14+
connection = cx_Oracle.connect(sample_env.get_main_connect_string())
1515

1616
rows = [ (1, "First" ),
1717
(2, "Second" ),

samples/BindQuery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#------------------------------------------------------------------------------
44

55
#------------------------------------------------------------------------------
@@ -13,9 +13,9 @@
1313
#------------------------------------------------------------------------------
1414

1515
import cx_Oracle
16-
import SampleEnv
16+
import sample_env
1717

18-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
18+
connection = cx_Oracle.connect(sample_env.get_main_connect_string())
1919

2020
cursor = connection.cursor()
2121
sql = 'select * from SampleQueryTab where id = :bvid'

samples/BulkAQ.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
#
44
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
55
#
@@ -17,7 +17,7 @@
1717
#------------------------------------------------------------------------------
1818

1919
import cx_Oracle
20-
import SampleEnv
20+
import sample_env
2121

2222
QUEUE_NAME = "DEMO_RAW_QUEUE"
2323
PAYLOAD_DATA = [
@@ -36,7 +36,7 @@
3636
]
3737

3838
# connect to database
39-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
39+
connection = cx_Oracle.connect(sample_env.get_main_connect_string())
4040
cursor = connection.cursor()
4141

4242
# create queue
@@ -51,22 +51,22 @@
5151

5252
# enqueue a few messages
5353
print("Enqueuing messages...")
54-
batchSize = 6
55-
dataToEnq = PAYLOAD_DATA
56-
while dataToEnq:
57-
batchData = dataToEnq[:batchSize]
58-
dataToEnq = dataToEnq[batchSize:]
59-
messages = [connection.msgproperties(payload=d) for d in batchData]
60-
for data in batchData:
54+
batch_size = 6
55+
data_to_enqueue = PAYLOAD_DATA
56+
while data_to_enqueue:
57+
batch_data = data_to_enqueue[:batch_size]
58+
data_to_enqueue = data_to_enqueue[batch_size:]
59+
messages = [connection.msgproperties(payload=d) for d in batch_data]
60+
for data in batch_data:
6161
print(data)
6262
queue.enqMany(messages)
6363
connection.commit()
6464

6565
# dequeue the messages
6666
print("\nDequeuing messages...")
67-
batchSize = 8
67+
batch_size = 8
6868
while True:
69-
messages = queue.deqMany(batchSize)
69+
messages = queue.deqMany(batch_size)
7070
if not messages:
7171
break
7272
for props in messages:

samples/CQN.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
#
44
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
55
#
@@ -18,7 +18,7 @@
1818
#------------------------------------------------------------------------------
1919

2020
import cx_Oracle
21-
import SampleEnv
21+
import sample_env
2222
import time
2323

2424
registered = True
@@ -47,7 +47,8 @@ def callback(message):
4747
print("-" * 60)
4848
print("=" * 60)
4949

50-
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString(), events = True)
50+
connection = cx_Oracle.connect(sample_env.get_main_connect_string(),
51+
events=True)
5152
sub = connection.subscribe(callback = callback, timeout = 1800,
5253
qos = cx_Oracle.SUBSCR_QOS_QUERY | cx_Oracle.SUBSCR_QOS_ROWIDS)
5354
print("Subscription:", sub)
@@ -64,4 +65,3 @@ def callback(message):
6465
while registered:
6566
print("Waiting for notifications....")
6667
time.sleep(5)
67-

samples/CQN2.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#------------------------------------------------------------------------------
1818

1919
import cx_Oracle
20-
import SampleEnv
20+
import sample_env
2121
import time
2222

2323
registered = True
@@ -34,11 +34,11 @@ def callback(message):
3434
if table.rows is None:
3535
print("Too many row changes detected in table", table.name)
3636
continue
37-
numRowsDeleted = 0
37+
num_rows_deleted = 0
3838
print(len(table.rows), "row changes detected in table", table.name)
3939
for row in table.rows:
4040
if row.operation & cx_Oracle.OPCODE_DELETE:
41-
numRowsDeleted += 1
41+
num_rows_deleted += 1
4242
continue
4343
ops = []
4444
if row.operation & cx_Oracle.OPCODE_INSERT:
@@ -51,21 +51,22 @@ def callback(message):
5151
from TestTempTable
5252
where rowid = :rid""",
5353
rid=row.rowid)
54-
intCol, = cursor.fetchone()
55-
print(" Row with IntCol", intCol, "was", " and ".join(ops))
56-
if numRowsDeleted > 0:
57-
print(" ", numRowsDeleted, "rows deleted")
54+
int_col, = cursor.fetchone()
55+
print(" Row with IntCol", int_col, "was", " and ".join(ops))
56+
if num_rows_deleted > 0:
57+
print(" ", num_rows_deleted, "rows deleted")
5858
print("=" * 60)
5959

60-
pool = cx_Oracle.SessionPool(SampleEnv.GetMainUser(),
61-
SampleEnv.GetMainPassword(), SampleEnv.GetConnectString(), min=2,
62-
max=5, increment=1, events=True, threaded=True)
60+
pool = cx_Oracle.SessionPool(user=sample_env.get_main_user(),
61+
password=sample_env.get_main_password(),
62+
dsn=sample_env.get_connect_string(), min=2,
63+
max=5, increment=1, events=True, threaded=True)
6364
with pool.acquire() as connection:
6465
sub = connection.subscribe(callback=callback, timeout=1800,
6566
qos=cx_Oracle.SUBSCR_QOS_QUERY | cx_Oracle.SUBSCR_QOS_ROWIDS)
6667
print("Subscription created with ID:", sub.id)
67-
queryId = sub.registerquery("select * from TestTempTable")
68-
print("Registered query with ID:", queryId)
68+
query_id = sub.registerquery("select * from TestTempTable")
69+
print("Registered query with ID:", query_id)
6970

7071
while registered:
7172
print("Waiting for notifications....")

0 commit comments

Comments
 (0)