Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
257f117c
Commit
257f117c
authored
10 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
Integrity error reparsing added
parent
a718b420
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
channels/sockets/sockets.py
+1
-3
1 addition, 3 deletions
channels/sockets/sockets.py
db/pool/__init__.py
+21
-1
21 additions, 1 deletion
db/pool/__init__.py
with
22 additions
and
4 deletions
channels/sockets/sockets.py
+
1
−
3
View file @
257f117c
...
...
@@ -279,9 +279,7 @@ class SelectHandlingLayer(HandlingLayer):
self
.
poll
=
select
.
poll
()
self
.
fdmap
=
{}
def
close
(
self
):
self
.
poll
.
close
()
def
register_channel
(
self
,
channel
):
"""
Registers a file descriptor based channel.
...
...
This diff is collapsed.
Click to expand it.
db/pool/__init__.py
+
21
−
1
View file @
257f117c
...
...
@@ -3,7 +3,7 @@ import Queue
class
DatabaseDefinition
(
object
):
def
__init__
(
self
,
cccall
,
cbexcepts
,
cccall_args
=
(),
cccall_kwargs
=
{},
xwcb
=
lambda
e
:
True
,
acs
=
lambda
x
:
None
,
occ
=
lambda
x
:
None
,
oct
=
lambda
x
:
None
):
oct
=
lambda
x
:
None
,
integ_err_cls
=
None
):
"""
This initializes a database definition. Because different databases work
...
...
@@ -45,6 +45,10 @@ class DatabaseDefinition(object):
at it
'
s default.
@type oct: callable/1
@param integ_err_cls: class of IntegrityError exceptions. If .execute() throws an
exception of this class, and it
'
s an instance of integ_err_cls, it will be rethrown
as given cursor
'
s IntegrityError exception
@type integ_err_cls: clas
"""
if
type
(
cbexcepts
)
in
(
tuple
,
list
):
self
.
cb_excepts
=
tuple
(
cbexcepts
)
...
...
@@ -56,6 +60,7 @@ class DatabaseDefinition(object):
self
.
occ
=
occ
self
.
oct
=
oct
self
.
conn_lambda
=
lambda
:
cccall
(
*
cccall_args
,
**
cccall_kwargs
)
#: closure that returns a connection
self
.
integ_err_cls
=
None
def
get_connection
(
self
):
"""
Returns a new connection object. This connects to the database with according
...
...
@@ -224,6 +229,10 @@ class ConnectionPool(object):
Supports the context manager protocol.
"""
class
IntegrityError
(
Exception
):
"""
Thrown when cursor raises an integrity error
"""
def
__init__
(
self
,
cp
):
"""
Initializes the cursor wrapper.
...
...
@@ -244,6 +253,8 @@ class ConnectionPool(object):
except
self
.
cp
.
dd
.
cb_excepts
as
exc
:
if
not
self
.
first_query
:
raise
if
not
self
.
cp
.
dd
.
xwcb
(
exc
):
raise
if
isinstance
(
exc
,
self
.
cp
.
dd
.
integ_err_cls
):
raise
self
.
IntegrityError
self
.
_reconnect
()
continue
self
.
first_query
=
False
...
...
@@ -256,6 +267,8 @@ class ConnectionPool(object):
except
self
.
cp
.
dd
.
cb_excepts
as
exc
:
if
not
self
.
first_query
:
raise
if
not
self
.
cp
.
dd
.
xwcb
(
exc
):
raise
if
isinstance
(
exc
,
self
.
cp
.
dd
.
integ_err_cls
):
raise
self
.
IntegrityError
self
.
_reconnect
()
continue
self
.
first_query
=
False
...
...
@@ -300,6 +313,9 @@ class ConnectionPool(object):
Supports the context manager protocol.
"""
class
IntegrityError
(
Exception
):
"""
Thrown when cursor raises an integrity error
"""
def
__init__
(
self
,
cp
):
super
(
Cursor
,
self
).
__init__
(
cp
,
False
)
...
...
@@ -309,6 +325,8 @@ class ConnectionPool(object):
self
.
cursor
.
execute
(
*
args
,
**
kwargs
)
except
self
.
cp
.
dd
.
cb_excepts
as
exc
:
if
not
self
.
cp
.
dd
.
xwcb
(
exc
):
raise
if
isinstance
(
exc
,
self
.
cp
.
dd
.
integ_err_cls
):
raise
self
.
IntegrityError
self
.
_reconnect
()
continue
break
...
...
@@ -319,6 +337,8 @@ class ConnectionPool(object):
self
.
cursor
.
executemany
(
*
args
,
**
kwargs
)
except
self
.
cp
.
dd
.
cb_excepts
as
exc
:
if
not
self
.
cp
.
dd
.
xwcb
(
exc
):
raise
if
isinstance
(
exc
,
self
.
cp
.
dd
.
integ_err_cls
):
raise
self
.
IntegrityError
self
.
_reconnect
()
continue
break
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment