FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-tools/voidpp_tools/alchemy_encoder.py at master · voidpp/python-tools · GitHub
voidpp
/
python-tools
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-tools
/
voidpp_tools
/
alchemy_encoder.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
19 lines (17 loc) · 742 Bytes
Breadcrumbs
python-tools
/
voidpp_tools
/
alchemy_encoder.py
Copy path
File metadata and controls
19 lines (17 loc) · 742 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import
json
from
sqlalchemy
.
ext
.
declarative
import
DeclarativeMeta
class
AlchemyEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
obj
):
if
isinstance
(
obj
.
__class__
,
DeclarativeMeta
):
# an SQLAlchemy class
fields
=
{}
for
field
in
[
x
for
x
in
dir
(
obj
)
if
not
x
.
startswith
(
'_'
)
and
x
!=
'metadata'
]:
data
=
obj
.
__getattribute__
(
field
)
try
:
json
.
dumps
(
data
)
# this will fail on non-encodable values, like other classes
fields
[
field
]
=
data
except
TypeError
:
fields
[
field
]
=
None
# a json-encodable dict
return
fields
return
json
.
JSONEncoder
.
default
(
self
,
obj
)
Back
|
FazBrowse Home
|
New Git URL