Commit 9f72d237 authored by Georg Brandl's avatar Georg Brandl

Use PEP 8.

parent 001e8388
...@@ -242,11 +242,11 @@ rolled back if there's an exception. Here's the basic interface for ...@@ -242,11 +242,11 @@ rolled back if there's an exception. Here's the basic interface for
class DatabaseConnection: class DatabaseConnection:
# Database interface # Database interface
def cursor (self): def cursor(self):
"Returns a cursor object and starts a new transaction" "Returns a cursor object and starts a new transaction"
def commit (self): def commit(self):
"Commits current transaction" "Commits current transaction"
def rollback (self): def rollback(self):
"Rolls back current transaction" "Rolls back current transaction"
The :meth:`__enter__` method is pretty easy, having only to start a new The :meth:`__enter__` method is pretty easy, having only to start a new
...@@ -256,7 +256,7 @@ their ':keyword:`with`' statement to bind the cursor to a variable name. :: ...@@ -256,7 +256,7 @@ their ':keyword:`with`' statement to bind the cursor to a variable name. ::
class DatabaseConnection: class DatabaseConnection:
... ...
def __enter__ (self): def __enter__(self):
# Code to start a new transaction # Code to start a new transaction
cursor = self.cursor() cursor = self.cursor()
return cursor return cursor
...@@ -273,7 +273,7 @@ add a :keyword:`return` statement at the marked location. :: ...@@ -273,7 +273,7 @@ add a :keyword:`return` statement at the marked location. ::
class DatabaseConnection: class DatabaseConnection:
... ...
def __exit__ (self, type, value, tb): def __exit__(self, type, value, tb):
if tb is None: if tb is None:
# No exception, so commit # No exception, so commit
self.commit() self.commit()
...@@ -306,7 +306,7 @@ decorator as:: ...@@ -306,7 +306,7 @@ decorator as::
from contextlib import contextmanager from contextlib import contextmanager
@contextmanager @contextmanager
def db_transaction (connection): def db_transaction(connection):
cursor = connection.cursor() cursor = connection.cursor()
try: try:
yield cursor yield cursor
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment