-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fp write for STIX Objects #500
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. Could the serialize()
function even be reimplemented to call fp_serialize()
and pass an io.StringIO
? That would remove the code duplication between the two functions.
I started with having both under a same function, but I was doubtful about having two different behaviors (one that returned a string and one that returned None). Based on the same idea that |
Codecov Report
@@ Coverage Diff @@
## master #500 +/- ##
==========================================
- Coverage 89.47% 89.47% -0.01%
==========================================
Files 147 147
Lines 16554 16599 +45
==========================================
+ Hits 14812 14852 +40
- Misses 1742 1747 +5
Continue to review full report at Codecov.
|
I didn't mean to combine them into one function. It was more like change the serialize() function to be something like: with io.StringIO() as fp:
fp_serialize(obj, fp)
return fp.getvalue() So the "main" code for serializing lives in one place, the two functions can't get out of sync, the serialize() implementation is shorter and simpler, etc. Just a thought. |
I misinterpreted your prior message. It is a good suggestion... |
Co-authored-by: Chris Lenk <clenk@users.noreply.github.com>
Adding this piece of code would help write more flexible code while also providing the same options as
serialize()