Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Knot DNS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Knot projects
Knot DNS
Commits
94dbffdf
Commit
94dbffdf
authored
Jan 09, 2017
by
Daniel Salzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python/control: raise KnotCtlError instead of general Exception
parent
a48b5325
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
6 deletions
+32
-6
python/libknot/control.py
python/libknot/control.py
+32
-6
No files found.
python/libknot/control.py
View file @
94dbffdf
...
...
@@ -80,6 +80,22 @@ def load_lib(path="libknot.so"):
CTL_ERROR
.
argtypes
=
[
c_int
]
class
KnotCtlError
(
Exception
):
"""Libknot server control error."""
def
__init__
(
self
,
message
,
data
=
None
):
"""
@type message: str
@type data: KnotCtlData
"""
self
.
message
=
message
self
.
data
=
data
def
__str__
(
self
):
return
"message: %s
\n
data: %s"
%
(
self
.
message
,
self
.
data
)
class
KnotCtlType
(
IntEnum
):
"""Libknot server control data unit types."""
...
...
@@ -113,6 +129,17 @@ class KnotCtlData(object):
def
__init__
(
self
):
self
.
data
=
self
.
DataArray
()
def
__str__
(
self
):
string
=
str
()
for
idx
in
KnotCtlDataIdx
:
if
self
.
data
[
idx
]:
if
string
:
string
+=
", "
string
+=
"%s = %s"
%
(
idx
.
name
,
self
.
data
[
idx
])
return
string
def
__getitem__
(
self
,
index
):
"""Data unit item getter.
...
...
@@ -162,7 +189,7 @@ class KnotCtl(object):
ret
=
CTL_CONNECT
(
self
.
obj
,
path
.
encode
())
if
ret
!=
0
:
err
=
CTL_ERROR
(
ret
)
raise
Exception
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
raise
KnotCtlError
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
def
close
(
self
):
"""Disconnects from the current control socket."""
...
...
@@ -180,7 +207,7 @@ class KnotCtl(object):
data
.
data
if
data
else
c_char_p
())
if
ret
!=
0
:
err
=
CTL_ERROR
(
ret
)
raise
Exception
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
raise
KnotCtlError
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
def
receive
(
self
,
data
=
None
):
"""Receives a data unit from the connected control socket.
...
...
@@ -194,7 +221,7 @@ class KnotCtl(object):
data
.
data
if
data
else
c_char_p
())
if
ret
!=
0
:
err
=
CTL_ERROR
(
ret
)
raise
Exception
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
raise
KnotCtlError
(
err
if
isinstance
(
err
,
str
)
else
err
.
decode
())
return
KnotCtlType
(
data_type
.
value
)
def
send_block
(
self
,
cmd
,
section
=
None
,
item
=
None
,
identifier
=
None
,
zone
=
None
,
...
...
@@ -344,7 +371,7 @@ class KnotCtl(object):
# Check for an error.
if
reply
[
KnotCtlDataIdx
.
ERROR
]:
raise
Exception
(
reply
[
KnotCtlDataIdx
.
ERROR
]
)
raise
KnotCtlError
(
reply
[
KnotCtlDataIdx
.
ERROR
],
reply
)
self
.
_receive_stats
(
out
,
reply
)
...
...
@@ -361,14 +388,13 @@ class KnotCtl(object):
while
True
:
reply
=
KnotCtlData
()
reply_type
=
self
.
receive
(
reply
)
# Stop if not data type.
if
reply_type
not
in
[
KnotCtlType
.
DATA
,
KnotCtlType
.
EXTRA
]:
break
# Check for an error.
if
reply
[
KnotCtlDataIdx
.
ERROR
]:
raise
Exception
(
reply
[
KnotCtlDataIdx
.
ERROR
]
)
raise
KnotCtlError
(
reply
[
KnotCtlDataIdx
.
ERROR
],
reply
)
# Check for config data.
if
reply
[
KnotCtlDataIdx
.
SECTION
]:
...
...
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