Skip to content

Commit

Permalink
Update HTTP annotation response router.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 20, 2017
1 parent 9d40edb commit bd7fd85
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions vision/google/cloud/vision/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Annotations management for Vision API responses."""

import six

from google.cloud.vision.color import ImagePropertiesAnnotation
from google.cloud.vision.entity import EntityAnnotation
Expand Down Expand Up @@ -86,14 +87,11 @@ def from_api_repr(cls, response):
:rtype: :class:`~google.cloud.vision.annotations.Annotations`
:returns: An instance of ``Annotations`` with detection types loaded.
"""
annotations = {}
for feature_type, annotation in response.items():
curr_feature = annotations.setdefault(_KEY_MAP[feature_type], [])
entity = _entity_from_response_type(feature_type, annotation)
if isinstance(entity, list):
curr_feature.extend(entity)
else:
annotations[_KEY_MAP[feature_type]] = entity
annotations = {
_KEY_MAP[feature_type]: _entity_from_response_type(
feature_type, annotation)
for feature_type, annotation in six.iteritems(response)
}
return cls(**annotations)

@classmethod
Expand Down

0 comments on commit bd7fd85

Please sign in to comment.