Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9f72d237
Commit
9f72d237
authored
Dec 16, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use PEP 8.
parent
001e8388
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
Doc/whatsnew/2.6.rst
Doc/whatsnew/2.6.rst
+6
-6
No files found.
Doc/whatsnew/2.6.rst
View file @
9f72d237
...
...
@@ -242,11 +242,11 @@ rolled back if there's an exception. Here's the basic interface for
class DatabaseConnection:
# Database interface
def cursor
(self):
def cursor(self):
"Returns a cursor object and starts a new transaction"
def commit
(self):
def commit(self):
"Commits current transaction"
def rollback
(self):
def rollback(self):
"Rolls back current transaction"
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. ::
class DatabaseConnection:
...
def __enter__
(self):
def __enter__(self):
# Code to start a new transaction
cursor = self.cursor()
return cursor
...
...
@@ -273,7 +273,7 @@ add a :keyword:`return` statement at the marked location. ::
class DatabaseConnection:
...
def __exit__
(self, type, value, tb):
def __exit__(self, type, value, tb):
if tb is None:
# No exception, so commit
self.commit()
...
...
@@ -306,7 +306,7 @@ decorator as::
from contextlib import contextmanager
@contextmanager
def db_transaction
(connection):
def db_transaction(connection):
cursor = connection.cursor()
try:
yield cursor
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment