Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Thomas Leymonerie
slapos.core
Commits
3cee3ff0
Commit
3cee3ff0
authored
May 04, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simpler _getDict with guards; correctly skip logger serialization
parent
056ceb46
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
19 deletions
+16
-19
slapos/format.py
slapos/format.py
+16
-19
No files found.
slapos/format.py
View file @
3cee3ff0
...
@@ -152,38 +152,35 @@ def netmaskToPrefixIPv6(netmask):
...
@@ -152,38 +152,35 @@ def netmaskToPrefixIPv6(netmask):
netaddr
.
strategy
.
ipv6
.
str_to_int
(
netmask
)]
netaddr
.
strategy
.
ipv6
.
str_to_int
(
netmask
)]
def
_getDict
(
instance
):
def
_getDict
(
obj
):
"""
"""
Serialize an object in
stance in
to dictionaries. List and dict will remains
Serialize an object into dictionaries. List and dict will remains
the same, basic type too. But encapsulated object will be returned as dict.
the same, basic type too. But encapsulated object will be returned as dict.
Set, collections and other aren't handle for now.
Set, collections and other aren't handle for now.
Args:
Args:
instance
: an object of any type.
obj
: an object of any type.
Returns:
Returns:
A dictionary if the given object wasn't a list, a list otherwise.
A dictionary if the given object wasn't a list, a list otherwise.
"""
"""
if
isinstance
(
instance
,
list
):
if
isinstance
(
obj
,
list
):
return
[
_getDict
(
item
)
for
item
in
instance
]
return
[
_getDict
(
item
)
for
item
in
obj
]
elif
isinstance
(
instance
,
dict
):
result
=
{}
for
key
in
instance
:
result
[
key
]
=
_getDict
(
instance
[
key
])
return
result
if
isinstance
(
obj
,
dict
):
dikt
=
obj
else
:
else
:
try
:
try
:
dikt
=
instance
.
__dict__
dikt
=
obj
.
__dict__
except
AttributeError
:
except
AttributeError
:
return
instance
return
obj
result
=
{}
for
key
,
value
in
dikt
.
iteritems
():
return
{
key
:
_getDict
(
value
)
for
key
,
value
in
dikt
.
iteritems
()
# do not attempt to serialize logger: it is both useless and recursive.
# do not attempt to serialize logger: it is both useless and recursive.
if
not
isinstance
(
instance
,
logging
.
Logger
):
if
not
isinstance
(
value
,
logging
.
Logger
)
result
[
key
]
=
_getDict
(
value
)
}
return
result
class
Computer
(
object
):
class
Computer
(
object
):
...
...
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