Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyoctofuss
Manage
Activity
Members
Labels
Plan
Issues
0
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FUSS
pyoctofuss
Commits
a04ccb79
Commit
a04ccb79
authored
8 years ago
by
Enrico Zini
Browse files
Options
Downloads
Patches
Plain Diff
Added a file of common exceptions usable also in xmlrpc
parent
7b7d75ac
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
octofuss/exceptions.py
+5
-0
5 additions, 0 deletions
octofuss/exceptions.py
octofuss/xmlrpc.py
+9
-1
9 additions, 1 deletion
octofuss/xmlrpc.py
tests/test_exception_serializer.py
+8
-0
8 additions, 0 deletions
tests/test_exception_serializer.py
with
22 additions
and
1 deletion
octofuss/exceptions.py
0 → 100644
+
5
−
0
View file @
a04ccb79
__all__
=
[
"
HomeDirectoryExistsError
"
]
class
HomeDirectoryExistsError
(
FileExistsError
):
pass
This diff is collapsed.
Click to expand it.
octofuss/xmlrpc.py
+
9
−
1
View file @
a04ccb79
...
...
@@ -3,6 +3,7 @@ from __future__ import (absolute_import, print_function, division, unicode_liter
from
json
import
dumps
,
loads
from
six.moves.xmlrpc_client
import
ServerProxy
import
octofuss
import
octofuss.exceptions
class
UnknownException
(
Exception
):
def
__init__
(
self
,
msg
):
...
...
@@ -16,13 +17,20 @@ class APIKeyException(Exception):
class
ExceptionSerializer
:
EXCEPTION_WHITELIST
=
[
Exception
,
UnknownException
,
LookupError
,
AttributeError
,
ValueError
,
KeyError
,
APIKeyException
Exception
,
UnknownException
,
LookupError
,
AttributeError
,
ValueError
,
KeyError
,
APIKeyException
,
]
def
__init__
(
self
):
self
.
by_class
=
{
c
:
c
.
__module__
+
"
.
"
+
c
.
__name__
for
c
in
self
.
EXCEPTION_WHITELIST
}
self
.
by_name
=
{
c
.
__module__
+
"
.
"
+
c
.
__name__
:
c
for
c
in
self
.
EXCEPTION_WHITELIST
}
# Add the exceptions from octofuss.exceptions
for
name
in
octofuss
.
exceptions
.
__all__
:
exc
=
getattr
(
octofuss
.
exceptions
,
name
)
name
=
"
octofuss.exceptions.
"
+
name
self
.
by_class
[
exc
]
=
name
self
.
by_name
[
name
]
=
exc
def
exception_name
(
self
,
exc
):
name
=
self
.
by_class
.
get
(
exc
)
if
name
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_exception_serializer.py
+
8
−
0
View file @
a04ccb79
import
unittest
from
octofuss.xmlrpc
import
ExceptionSerializer
,
APIKeyException
,
UnknownException
import
octofuss.exceptions
class
TestSerialize
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -19,6 +20,9 @@ class TestSerialize(unittest.TestCase):
d
=
self
.
ser
.
to_dict
(
APIKeyException
(
"
test
"
))
self
.
assertEquals
(
d
,
{
"
name
"
:
"
octofuss.xmlrpc.APIKeyException
"
,
"
msg
"
:
"
test
"
})
d
=
self
.
ser
.
to_dict
(
octofuss
.
exceptions
.
HomeDirectoryExistsError
(
"
test
"
))
self
.
assertEquals
(
d
,
{
"
name
"
:
"
octofuss.exceptions.HomeDirectoryExistsError
"
,
"
msg
"
:
"
test
"
})
def
test_unknown
(
self
):
d
=
self
.
ser
.
to_dict
(
42
)
self
.
assertEquals
(
d
,
{
"
name
"
:
"
octofuss.xmlrpc.UnknownException
"
,
"
msg
"
:
"
42
"
})
...
...
@@ -37,6 +41,10 @@ class TestDeserialize(unittest.TestCase):
self
.
assertEquals
(
e
.
__class__
,
APIKeyException
)
self
.
assertEquals
(
e
.
args
[
0
],
"
test
"
)
e
=
self
.
ser
.
from_dict
({
"
name
"
:
"
octofuss.exceptions.HomeDirectoryExistsError
"
,
"
msg
"
:
"
test
"
})
self
.
assertEquals
(
e
.
__class__
,
octofuss
.
exceptions
.
HomeDirectoryExistsError
)
self
.
assertEquals
(
e
.
args
[
0
],
"
test
"
)
def
test_unknown
(
self
):
e
=
self
.
ser
.
from_dict
({
"
name
"
:
"
octofuss.xmlrpc.UnknownException
"
,
"
msg
"
:
"
42
"
})
self
.
assertEquals
(
e
.
__class__
,
UnknownException
)
...
...
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