-
Notifications
You must be signed in to change notification settings - Fork 180
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
Issue #96: Add port support #97
Conversation
/cc @RussTheAerialist @geordielad |
self._port = value | ||
# If port is None we don't actually want to update the XML | ||
if value is not None: | ||
self._connectionXML.set('port', value) |
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.
How do you remove the port if it exists and you want to remove it?
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.
Hmm. I can invert the logic so that it's:
@port.setter
def port(self, value):
self._port = value
# If port is None we remove the element and don't write it to XML
if value is None:
try:
self._connectionXML.attrib.pop('port')
except KeyError:
pass
else:
self._connectionXML.set('port', value)
EDIT: This is an implementation that passes tests
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.
That would be good, though I prefer this semantic for deleting rather than poping
del self._connectionXML.attrib['port']
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.
Done -- one SO post said del doesn't work, but others said it's fine and it works for me too
@@ -30,18 +30,20 @@ def __init__(self, connxml): | |||
self._username = connxml.get('username') | |||
self._authentication = connxml.get('authentication') | |||
self._class = connxml.get('class') | |||
self.port = connxml.get('port', None) |
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.
should this be self._port?
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 originally I didn't so that validation logic would get triggered, but with my new "Don't write it" approach I think I can do just _port
now.
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.
🚀
Addresses #96
Adding support for reading the
port
attribute from connections that have one.We keep
None
in the model for cases where there is no port, but that won't get written to the XML.Setting it to any other value will be persisted in the XML
This is a minimal change to resolve the issue -- I realize that we could do some cleanup on class construction like in the client-python-lib, but I don't think it's necessary in this PR