Skip to content

Commit

Permalink
Moving old function into _non_upstream_helpers.
Browse files Browse the repository at this point in the history
It's been moved into core.
  • Loading branch information
dhermes committed Jan 20, 2016
1 parent 4286446 commit 4b6c120
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 24 additions & 0 deletions gcloud_bigtable/_non_upstream_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,27 @@ def _pb_timestamp_to_datetime(timestamp):
microseconds=(timestamp.nanos / 1000.0),
)
)


def _get_pb_property_value(message_pb, property_name):
"""Return a message field value.
:type message_pb: :class:`google.protobuf.message.Message`
:param message_pb: The message to check for ``property_name``.
:type property_name: str
:param property_name: The property value to check against.
:rtype: object
:returns: The value of ``property_name`` set on ``message_pb``.
:raises: :class:`ValueError <exceptions.ValueError>` if the result returned
from the ``message_pb`` does not contain the ``property_name``
value.
"""
# Make sure `property_name` is set on the response.
# NOTE: As of proto3, HasField() only works for message fields, not for
# singular (non-message) fields.
all_fields = set([field.name for field in message_pb._fields])
if property_name not in all_fields:
raise ValueError('Message does not contain %s.' % (property_name,))
return getattr(message_pb, property_name)
25 changes: 1 addition & 24 deletions gcloud_bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
bigtable_cluster_service_messages_pb2 as messages_pb2)
from gcloud_bigtable._generated import (
bigtable_table_service_messages_pb2 as table_messages_pb2)
from gcloud_bigtable._non_upstream_helpers import _get_pb_property_value
from gcloud_bigtable._non_upstream_helpers import _pb_timestamp_to_datetime
from gcloud_bigtable.table import Table

Expand All @@ -47,30 +48,6 @@
}


def _get_pb_property_value(message_pb, property_name):
"""Return a message field value.
:type message_pb: :class:`google.protobuf.message.Message`
:param message_pb: The message to check for ``property_name``.
:type property_name: str
:param property_name: The property value to check against.
:rtype: object
:returns: The value of ``property_name`` set on ``message_pb``.
:raises: :class:`ValueError <exceptions.ValueError>` if the result returned
from the ``message_pb`` does not contain the ``property_name``
value.
"""
# Make sure `property_name` is set on the response.
# NOTE: As of proto3, HasField() only works for message fields, not for
# singular (non-message) fields.
all_fields = set([field.name for field in message_pb._fields])
if property_name not in all_fields:
raise ValueError('Message does not contain %s.' % (property_name,))
return getattr(message_pb, property_name)


def _prepare_create_request(cluster):
"""Creates a protobuf request for a CreateCluster request.
Expand Down

0 comments on commit 4b6c120

Please sign in to comment.