Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Further avatar fixes and improvements #63

Merged
merged 14 commits into from
Apr 4, 2017
Merged

Further avatar fixes and improvements #63

merged 14 commits into from
Apr 4, 2017

Conversation

sebastianriese
Copy link
Collaborator

@sebastianriese sebastianriese commented Mar 29, 2017

  • fix the set_avatar.py example
  • some refactoring
  • fix some documentation issues
  • fix style issues
  • fix get_avatar_metdata(..., require_fresh=True)
  • fixes #59

sebastianriese and others added 2 commits March 29, 2017 20:19
* they where parsed to bytes before, but since they are
  reused as ids and the encoding is not uniquely defined
  in the XEP, we preserve the original string for interaction
  with pubsub and define an normalized_id property on
  AbstractAvatarHandle, which can be used for caching.
Copy link
Owner

@horazont horazont left a comment

Choose a reason for hiding this comment

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

Two nits and a question.

"""

def __init__(self, remote_jid, mime_type, id_, nbytes, width=None,
height=None, url=None, pubsub=None):
self._remote_jid = remote_jid
self._mime_type = mime_type
self._id = id_
self._normalized_id = normalize_id(self._id)
Copy link
Owner

Choose a reason for hiding this comment

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

Handle it in the property function. If it is a performance concern at some point, we can still fix it.

except KeyError:
pass
with (yield from self._lock):
if jid in self._metadata_cache:
Copy link
Owner

Choose a reason for hiding this comment

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

I feel this can be written down nicer with try. Maybe:

if require_fresh:
    self._metadata_cache.pop(jid, None)
else:
    try:
        return self._metadata_cache[jid]
    except KeyError:
        pass

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, pop of course has the notion of using the value we pop off the dict, instead of just discarding it. I think the explicit test is the right way to go here (and shorter!).

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, if you prefer it that way it’s fine.

avatar_xso.Data(avatar_set.image_bytes),
id_=id_
)
with (yield from self._lock):
Copy link
Owner

Choose a reason for hiding this comment

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

This still lacks the race condition fix if we race with other clients, right? Do you plan to do this in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope. This will probably need a new pull request an possible additional support from PubSub (but I'll have to read the PubSub spec to be sure). As I do not want to download the image data to verify it matches, but simply check whether the image data pubsub item has the appropriate id.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually, I wonder whether we already get a push notification with the avatar data or at least the item ID because PEP. Can you investigate that? Does that even help us? (I’m not sure about that.)

Downloading the full avatar does seem like not a very bad thing to do here, unless we find a saner way. Matching the metadata won’t be sufficient to detect more than half of the collision scenarios.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

XEP-0163 section 3 is a bit unclear on whether we always get a notification:

If the publication logic dictates that event notifications shall be sent, the account owner's server generates notifications and sends them to all appropriate entities as described in the Receiving Event Notifications section of this document, as well as to any of the account owner's available resources.

If we would get a notification about the data, it would be easy to check consistency. If the server is clever enough to not send the payload along (but only notify about the ID), this would be the desired behaviour.

Copy link
Owner

@horazont horazont left a comment

Choose a reason for hiding this comment

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

Found a few test style nits to pick.

@@ -186,22 +196,61 @@ def test_png_id_is_normalized(self):
)

def test_error_checking(self):
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer to have those tests (a) in individual test case methods and (b) using assertRaisesRegex to at least roughly check you are catching the error you are expecting to catch.

  • (a) brings the advantage of overview if a single condition is violated and sense of graveness if the whole method is borked
  • (b) helps with testing that it’s not a "raise RuntimeError()" at the beginning but actual different code paths being taken

@@ -419,6 +489,19 @@ def test_get_image_bytes(self):
)
self.assertEqual(res, TEST_IMAGE)

def test_HttpAvatarDescriptr(self):
Copy link
Owner

Choose a reason for hiding this comment

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

Typo in method name (Descriptor vs. Descriptr)

@horazont
Copy link
Owner

horazont commented Apr 4, 2017

Github claims one of my comments is outdated, but I don’t think it in fact is.

@horazont horazont merged commit 3f8705a into devel Apr 4, 2017
@horazont horazont deleted the feature/avatar branch April 11, 2017 14:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[XEP-0084] Allow access to the original id (sha-1 of the image) to prevent issues with case sensitivity
2 participants