Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/boto/dynamodb/schema.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 # Copyright (c) 2011 Mitch Garnaat http://garnaat.org/ | |
| 2 # Copyright (c) 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved | |
| 3 # | |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | |
| 5 # copy of this software and associated documentation files (the | |
| 6 # "Software"), to deal in the Software without restriction, including | |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- | |
| 10 # lowing conditions: | |
| 11 # | |
| 12 # The above copyright notice and this permission notice shall be included | |
| 13 # in all copies or substantial portions of the Software. | |
| 14 # | |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| 21 # IN THE SOFTWARE. | |
| 22 # | |
| 23 | |
| 24 | |
| 25 class Schema(object): | |
| 26 """ | |
| 27 Represents a DynamoDB schema. | |
| 28 | |
| 29 :ivar hash_key_name: The name of the hash key of the schema. | |
| 30 :ivar hash_key_type: The DynamoDB type specification for the | |
| 31 hash key of the schema. | |
| 32 :ivar range_key_name: The name of the range key of the schema | |
| 33 or None if no range key is defined. | |
| 34 :ivar range_key_type: The DynamoDB type specification for the | |
| 35 range key of the schema or None if no range key is defined. | |
| 36 :ivar dict: The underlying Python dictionary that needs to be | |
| 37 passed to Layer1 methods. | |
| 38 """ | |
| 39 | |
| 40 def __init__(self, schema_dict): | |
| 41 self._dict = schema_dict | |
| 42 | |
| 43 def __repr__(self): | |
| 44 if self.range_key_name: | |
| 45 s = 'Schema(%s:%s)' % (self.hash_key_name, self.range_key_name) | |
| 46 else: | |
| 47 s = 'Schema(%s)' % self.hash_key_name | |
| 48 return s | |
| 49 | |
| 50 @classmethod | |
| 51 def create(cls, hash_key, range_key=None): | |
| 52 """Convenience method to create a schema object. | |
| 53 | |
| 54 Example usage:: | |
| 55 | |
| 56 schema = Schema.create(hash_key=('foo', 'N')) | |
| 57 schema2 = Schema.create(hash_key=('foo', 'N'), | |
| 58 range_key=('bar', 'S')) | |
| 59 | |
| 60 :type hash_key: tuple | |
| 61 :param hash_key: A tuple of (hash_key_name, hash_key_type) | |
| 62 | |
| 63 :type range_key: tuple | |
| 64 :param hash_key: A tuple of (range_key_name, range_key_type) | |
| 65 | |
| 66 """ | |
| 67 reconstructed = { | |
| 68 'HashKeyElement': { | |
| 69 'AttributeName': hash_key[0], | |
| 70 'AttributeType': hash_key[1], | |
| 71 } | |
| 72 } | |
| 73 if range_key is not None: | |
| 74 reconstructed['RangeKeyElement'] = { | |
| 75 'AttributeName': range_key[0], | |
| 76 'AttributeType': range_key[1], | |
| 77 } | |
| 78 instance = cls(None) | |
| 79 instance._dict = reconstructed | |
| 80 return instance | |
| 81 | |
| 82 @property | |
| 83 def dict(self): | |
| 84 return self._dict | |
| 85 | |
| 86 @property | |
| 87 def hash_key_name(self): | |
| 88 return self._dict['HashKeyElement']['AttributeName'] | |
| 89 | |
| 90 @property | |
| 91 def hash_key_type(self): | |
| 92 return self._dict['HashKeyElement']['AttributeType'] | |
| 93 | |
| 94 @property | |
| 95 def range_key_name(self): | |
| 96 name = None | |
| 97 if 'RangeKeyElement' in self._dict: | |
| 98 name = self._dict['RangeKeyElement']['AttributeName'] | |
| 99 return name | |
| 100 | |
| 101 @property | |
| 102 def range_key_type(self): | |
| 103 type = None | |
| 104 if 'RangeKeyElement' in self._dict: | |
| 105 type = self._dict['RangeKeyElement']['AttributeType'] | |
| 106 return type | |
| 107 | |
| 108 def __eq__(self, other): | |
| 109 return (self.hash_key_name == other.hash_key_name and | |
| 110 self.hash_key_type == other.hash_key_type and | |
| 111 self.range_key_name == other.range_key_name and | |
| 112 self.range_key_type == other.range_key_type) |
