當前位置: 首頁>>代碼示例>>Python>>正文


Python messages.Enum方法代碼示例

本文整理匯總了Python中protorpc.messages.Enum方法的典型用法代碼示例。如果您正苦於以下問題:Python messages.Enum方法的具體用法?Python messages.Enum怎麽用?Python messages.Enum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在protorpc.messages的用法示例。


在下文中一共展示了messages.Enum方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def __init__(self, enum_type, name=None, default=None, choices=None, **kwds):
    """Constructor.

    Args:
      enum_type: A subclass of protorpc.messages.Enum.
      name: Optional datastore name (defaults to the property name).

    Additional keywords arguments specify the same options as
    supported by IntegerProperty.
    """
    self._enum_type = enum_type
    if default is not None:
      self._validate(default)
    if choices is not None:
      map(self._validate, choices)
    super(EnumProperty, self).__init__(name, default=default,
                                       choices=choices, **kwds) 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:19,代碼來源:msgprop.py

示例2: testDefineMessageEnumOnly

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testDefineMessageEnumOnly(self):
    """Test definition a message with only enums."""

    class AMessage(messages.Message):
      class NestedEnum(messages.Enum):
        pass

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
開發者ID:google,項目名稱:protorpc,代碼行數:18,代碼來源:definition_test.py

示例3: testDefineMessage

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testDefineMessage(self):
    """Test defining Message class from descriptor."""

    class AMessage(messages.Message):
      class NestedEnum(messages.Enum):
        pass

      field1 = messages.IntegerField(1)
      field2 = messages.StringField(2)

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
開發者ID:google,項目名稱:protorpc,代碼行數:21,代碼來源:definition_test.py

示例4: testComparison

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testComparison(self):
    """Test comparing various enums to different types."""
    class Enum1(messages.Enum):
      VAL1 = 1
      VAL2 = 2

    class Enum2(messages.Enum):
      VAL1 = 1

    self.assertEquals(Enum1.VAL1, Enum1.VAL1)
    self.assertNotEquals(Enum1.VAL1, Enum1.VAL2)
    self.assertNotEquals(Enum1.VAL1, Enum2.VAL1)
    self.assertNotEquals(Enum1.VAL1, 'VAL1')
    self.assertNotEquals(Enum1.VAL1, 1)
    self.assertNotEquals(Enum1.VAL1, 2)
    self.assertNotEquals(Enum1.VAL1, None)
    self.assertNotEquals(Enum1.VAL1, Enum2.VAL1)

    self.assertTrue(Enum1.VAL1 < Enum1.VAL2)
    self.assertTrue(Enum1.VAL2 > Enum1.VAL1)

    self.assertNotEquals(1, Enum2.VAL1) 
開發者ID:google,項目名稱:protorpc,代碼行數:24,代碼來源:messages_test.py

示例5: testMessageField_WrongType

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testMessageField_WrongType(self):
    """Test that forward referencing the wrong type raises an error."""
    global AnEnum
    try:
      class AnEnum(messages.Enum):
        pass

      class AnotherMessage(messages.Message):

        a_field = messages.MessageField('AnEnum', 1)

      self.assertRaises(messages.FieldDefinitionError,
                        getattr,
                        AnotherMessage.field_by_name('a_field'),
                        'type')
    finally:
      del AnEnum 
開發者ID:google,項目名稱:protorpc,代碼行數:19,代碼來源:messages_test.py

示例6: testAllowNestedEnums

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testAllowNestedEnums(self):
    """Test allowing nested enums in a message definition."""
    class Trade(messages.Message):
      class Duration(messages.Enum):
        GTC = 1
        DAY = 2

      class Currency(messages.Enum):
        USD = 1
        GBP = 2
        INR = 3

    # Sorted by name order seems to be the only feasible option.
    self.assertEquals(['Currency', 'Duration'], Trade.__enums__)

    # Message definition will now be set on Enumerated objects.
    self.assertEquals(Trade, Trade.Duration.message_definition()) 
開發者ID:google,項目名稱:protorpc,代碼行數:19,代碼來源:messages_test.py

示例7: testDefault_EnumField

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testDefault_EnumField(self):
    class MyEnum(messages.Enum):

      VAL = 1

    module_name = test_util.get_module_name(MyEnum)
    field = messages.EnumField(MyEnum, 10, default=MyEnum.VAL)
    field.name = 'a_field'

    expected = descriptor.FieldDescriptor()
    expected.name = 'a_field'
    expected.number = 10
    expected.label = descriptor.FieldDescriptor.Label.OPTIONAL
    expected.variant = messages.EnumField.DEFAULT_VARIANT
    expected.type_name = '%s.MyEnum' % module_name
    expected.default_value = '1'

    described = descriptor.describe_field(field)
    self.assertEquals(expected, described) 
開發者ID:google,項目名稱:protorpc,代碼行數:21,代碼來源:descriptor_test.py

示例8: testNestedEnum

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testNestedEnum(self):
    class MessageWithEnum(messages.Message):
      class Mood(messages.Enum):
        GOOD = 1
        BAD = 2
        UGLY = 3

      class Music(messages.Enum):
        CLASSIC = 1
        JAZZ = 2
        BLUES = 3

    expected = descriptor.MessageDescriptor()
    expected.name = 'MessageWithEnum'

    expected.enum_types = [descriptor.describe_enum(MessageWithEnum.Mood),
                           descriptor.describe_enum(MessageWithEnum.Music)]

    described = descriptor.describe_message(MessageWithEnum)
    described.check_initialized()
    self.assertEquals(expected, described) 
開發者ID:google,項目名稱:protorpc,代碼行數:23,代碼來源:descriptor_test.py

示例9: testEnums

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def testEnums(self):
    """Test that enums are described."""
    module = self.LoadModule('my.package',
                             'class Enum1(messages.Enum): pass\n'
                             'class Enum2(messages.Enum): pass\n')

    enum1 = descriptor.EnumDescriptor()
    enum1.name = 'Enum1'

    enum2 = descriptor.EnumDescriptor()
    enum2.name = 'Enum2'

    expected = descriptor.FileDescriptor()
    expected.package = 'my.package'
    expected.enum_types = [enum1, enum2]

    described = descriptor.describe_file(module)
    described.check_initialized()
    self.assertEquals(expected, described) 
開發者ID:google,項目名稱:protorpc,代碼行數:21,代碼來源:descriptor_test.py

示例10: _serialize

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def _serialize(value):
  """Serializes a complex ndb type.

  Args:
    value: A ndb type to be serialized.

  Returns:
    Value serialized to simple data type such as integer or string.
  """
  if isinstance(value, datetime.datetime):
    return utils.datetime_to_unix(value)
  elif isinstance(value, (ndb.Key, ndb.GeoPt, messages.Enum)):
    return str(value)
  else:
    return value 
開發者ID:google,項目名稱:loaner,代碼行數:17,代碼來源:base_model.py

示例11: EnumPropertyHandler

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def EnumPropertyHandler(obj):
    """Serialize datetime objects."""
    return obj.name if isinstance(obj, messages.Enum) else obj 
開發者ID:googlearchive,項目名稱:billing-export-python,代碼行數:5,代碼來源:main.py

示例12: _validate

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def _validate(self, value):
    """Validate an Enum value.

    Raises:
      TypeError if the value is not an instance of self._enum_type.
    """
    if not isinstance(value, self._enum_type):
      raise TypeError('Expected a %s instance, got %r instead' %
                      (self._enum_type.__name__, value)) 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:11,代碼來源:msgprop.py

示例13: _to_base_type

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def _to_base_type(self, enum):
    """Convert an Enum value to a base type (integer) value."""
    return enum.number 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:5,代碼來源:msgprop.py

示例14: _from_base_type

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def _from_base_type(self, val):
    """Convert a base type (integer) value to an Enum value."""
    return self._enum_type(val) 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:5,代碼來源:msgprop.py

示例15: setUp

# 需要導入模塊: from protorpc import messages [as 別名]
# 或者: from protorpc.messages import Enum [as 別名]
def setUp(self):
    """Set up tests."""
    # Redefine Color class in case so that changes to it (an error) in one test
    # does not affect other tests.
    global Color
    class Color(messages.Enum):
      RED = 20
      ORANGE = 2
      YELLOW = 40
      GREEN = 4
      BLUE = 50
      INDIGO = 5
      VIOLET = 80 
開發者ID:google,項目名稱:protorpc,代碼行數:15,代碼來源:messages_test.py


注:本文中的protorpc.messages.Enum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。