-
Notifications
You must be signed in to change notification settings - Fork 51
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
XMLAdapterMixin implementation with xmltodict #87
Conversation
if 'headers' not in arguments: | ||
# allows user to override for formats like 'application/atom+xml' | ||
arguments['headers'] = {} | ||
arguments['headers']['Content-Type'] = 'application/xml' |
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.
Shouldn't this be one level of indentation down? I user needs to override it may call super and then alter.
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.
Good point, that is a better solution. I've made the change.
Before the fix, with line 135 inside the if statement, headers could be overridden at runtime (if no super calls set the headers) - this was the use case I was going after:
ipython console:
a = api.manage_worksheets(key='my_key').post(
data=x, headers={'Content-Type': 'application/atom+xml'})
After the fix, it's up to the wrapper developer to ensure that get_request_kwargs
correctly defines the headers, and the user of the api wrapper won't have to think about it:
tapioca_gheets.py/GsheetsClientAdapter/get_request_kwargs:
params['headers'] = {'Content-Type': 'application/atom+xml'}
95f8fbc Adds a new feature for wrapper developers to pass keyword arguments into XMLAdapterMixin looks for specifically prefixed keywords, removes them from the keyword dictionary that is passed to requests, and passes the suffixes and values directly to xmltodict.parse / unparse as keyword arguments. There are two special prefixes The wrapper developer can set these parameters inside of their tapioca_gsheets.py/GsheetsClientAdapter/get_request_kwargs:
This approach allows the wrapper developer to control input and output by passing any parameter they need into xmltodict.parse or unparse without limitation. See xmltodict source for options |
|
||
class XMLAdapterMixin(object): | ||
|
||
def __init__(self, serializer_class=None, *args, **kwargs): |
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.
Is this necessary?
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 think this can be removed safely.
Took me a while but i got the idea of the Changing this arguments would provoke changes in the way the developer interact with the wrapper? |
@filipeximenes - I thought about this and I think we can add a small number of parameters (and only one, if it's acceptable to force utf-8) instead of using this catch-all approach to address your concern. After reviewing, we probably won't need too much beyond The story behind Opting to give the developer full control of The original requirement I encountered was to remove the XML declaration (example: |
My only concern here is about simplicity:
If those 2 things are being respected, I'm ok with it. Does this make sense? |
@willplaehn happy PR anniversary! hahaha |
An XMLAdapterMixin that leverages xmltodict for input and output. #78
It can accept either an XML string, or a dictionary formatted per xmltodict's documentation.
This implementation truncates the output of
xmltodict.unparse
(removes the XML declaration and newline character) due to incompatibility with the Google Sheets API I was testing with.Considerations: