Skip to content
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

Merged
merged 3 commits into from
Oct 17, 2016
Merged

Issue #96: Add port support #97

merged 3 commits into from
Oct 17, 2016

Conversation

t8y8
Copy link
Contributor

@t8y8 t8y8 commented Oct 17, 2016

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

@t8y8
Copy link
Contributor Author

t8y8 commented Oct 17, 2016

/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)
Copy link
Contributor

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?

Copy link
Contributor Author

@t8y8 t8y8 Oct 17, 2016

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

Copy link
Contributor

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']

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@graysonarts graysonarts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@t8y8 t8y8 merged commit 1aa4fc0 into tableau:development Oct 17, 2016
@t8y8 t8y8 deleted the 96-port-support branch October 17, 2016 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants