本文整理汇总了Python中pycassa.marshal.packer_for函数的典型用法代码示例。如果您正苦于以下问题:Python packer_for函数的具体用法?Python packer_for怎么用?Python packer_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了packer_for函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_default_validation_class
def _set_default_validation_class(self, t):
if isinstance(t, types.CassandraType):
self._default_validation_class = t
self._default_value_packer = t.pack
self._default_value_unpacker = t.unpack
have_counters = isinstance(t, types.CounterColumnType)
else:
self._default_validation_class = marshal.extract_type_name(t)
self._default_value_packer = marshal.packer_for(t)
self._default_value_unpacker = marshal.unpacker_for(t)
have_counters = self._default_validation_class == "CounterColumnType"
if not self.super:
if have_counters:
def _make_cosc(name, value, timestamp, ttl):
return ColumnOrSuperColumn(counter_column=CounterColumn(name, value))
else:
def _make_cosc(name, value, timestamp, ttl):
return ColumnOrSuperColumn(Column(name, value, timestamp, ttl))
self._make_cosc = _make_cosc
else:
if have_counters:
def _make_column(name, value, timestamp, ttl):
return CounterColumn(name, value)
self._make_column = _make_column
def _make_cosc(scol_name, subcols):
return ColumnOrSuperColumn(counter_super_column=(SuperColumn(scol_name, subcols)))
else:
self._make_column = Column
def _make_cosc(scol_name, subcols):
return ColumnOrSuperColumn(super_column=(SuperColumn(scol_name, subcols)))
self._make_cosc = _make_cosc
示例2: __init__
def __init__(self, reversed=False, default=None):
self.reversed = reversed
self.default = default
if not hasattr(self.__class__, 'pack'):
self.pack = marshal.packer_for(self.__class__.__name__)
if not hasattr(self.__class__, 'unpack'):
self.unpack = marshal.unpacker_for(self.__class__.__name__)
示例3: __setitem__
def __setitem__(self, item, value):
if isinstance(value, types.CassandraType):
self.type_map[item] = value
self.packers[item] = value.pack
self.unpackers[item] = value.unpack
else:
self.type_map[item] = marshal.extract_type_name(value)
self.packers[item] = marshal.packer_for(value)
self.unpackers[item] = marshal.unpacker_for(value)
示例4: _set_key_validation_class
def _set_key_validation_class(self, t):
if isinstance(t, types.CassandraType):
self._key_validation_class = t
self._key_packer = t.pack
self._key_unpacker = t.unpack
else:
self._key_validation_class = marshal.extract_type_name(t)
self._key_packer = marshal.packer_for(t)
self._key_unpacker = marshal.unpacker_for(t)
示例5: _set_super_column_name_class
def _set_super_column_name_class(self, t):
if isinstance(t, types.CassandraType):
self._super_column_name_class = t
self._super_name_packer = t.pack
self._super_name_unpacker = t.unpack
else:
self._super_column_name_class = marshal.extract_type_name(t)
self._super_name_packer = marshal.packer_for(t)
self._super_name_unpacker = marshal.unpacker_for(t)
示例6: _alter_column_cfdef
def _alter_column_cfdef(self, cfdef, column, value_type):
if cfdef.column_type == 'Super':
packer = marshal.packer_for(cfdef.subcomparator_type)
else:
packer = marshal.packer_for(cfdef.comparator_type)
packed_column = packer(column)
value_type = self._qualify_type_class(value_type)
matched = False
for c in cfdef.column_metadata:
if c.name == packed_column:
c.validation_class = value_type
matched = True
break
if not matched:
cfdef.column_metadata.append(ColumnDef(packed_column, value_type, None, None))
return cfdef
示例7: alter_column
def alter_column(self, keyspace, column_family, column, value_type):
"""
Sets a data type for the value of a specific column.
`value_type` is a string that determines what type the column value will be.
By default, :const:`LONG_TYPE`, :const:`INT_TYPE`,
:const:`ASCII_TYPE`, :const:`UTF8_TYPE`, :const:`TIME_UUID_TYPE`,
:const:`LEXICAL_UUID_TYPE` and :const:`BYTES_TYPE` are provided. Custom
types may be used as well by providing the class name; if the custom
comparator class is not in ``org.apache.cassandra.db.marshal``, the fully
qualified class name must be given.
For super column families, this sets the subcolumn value type for
any subcolumn named `column`, regardless of the super column name.
"""
self._conn.set_keyspace(keyspace)
cfdef = self.get_keyspace_column_families(keyspace)[column_family]
if cfdef.column_type == 'Super':
packer = marshal.packer_for(cfdef.subcomparator_type)
else:
packer = marshal.packer_for(cfdef.comparator_type)
packed_column = packer(column)
value_type = self._qualify_type_class(value_type)
matched = False
for c in cfdef.column_metadata:
if c.name == packed_column:
c.validation_class = value_type
matched = True
break
if not matched:
cfdef.column_metadata.append(ColumnDef(packed_column, value_type, None, None))
self._system_update_column_family(cfdef)
示例8: create_index
def create_index(self, keyspace, column_family, column, value_type,
index_type=KEYS_INDEX, index_name=None):
"""
Creates an index on a column.
This allows efficient for index usage via
:meth:`~pycassa.columnfamily.ColumnFamily.get_indexed_slices()`
`column` specifies what column to index, and `value_type` is a string
that describes that column's value's data type; see
:meth:`alter_column()` for a full description of `value_type`.
`index_type` determines how the index will be stored internally. Currently,
:const:`KEYS_INDEX` is the only option. `index_name` is an optional name
for the index.
Example Usage:
.. code-block:: python
>>> from pycassa.system_manager import *
>>> sys = SystemManager('192.168.2.10:9160')
>>> sys.create_index('Keyspace1', 'Standard1', 'birthdate', LONG_TYPE, index_name='bday_index')
>>> sys.close
"""
self._conn.set_keyspace(keyspace)
cfdef = self.get_keyspace_column_families(keyspace)[column_family]
packer = marshal.packer_for(cfdef.comparator_type)
packed_column = packer(column)
value_type = self._qualify_type_class(value_type)
coldef = ColumnDef(packed_column, value_type, index_type, index_name)
for c in cfdef.column_metadata:
if c.name == packed_column:
cfdef.column_metadata.remove(c)
break
cfdef.column_metadata.append(coldef)
self._system_update_column_family(cfdef)
示例9: __init__
def __init__(self, reversed=False, default=None):
"""
A data type that Cassandra is aware of and knows
how to validate and sort.
If `reversed` is true and this is used as a column comparator,
the columns will be sorted in reverse order.
This is also used to specify fields to be persisted when
a class is used with :class:`~.ColumnFamilyMap`.
The `default` parameter only applies to use of this
with ColumnFamilyMap, where `default` is used if a row
does not contain a column corresponding to this item.
.. versionadded:: 1.2.0
"""
self.reversed = reversed
self.default = default
self.pack = marshal.packer_for(self.__class__.__name__)
self.unpack = marshal.unpacker_for(self.__class__.__name__)
示例10: __init__
def __init__(self, reversed=False, default=None):
self.reversed = reversed
self.default = default
self.pack = marshal.packer_for(self.__class__.__name__)
self.unpack = marshal.unpacker_for(self.__class__.__name__)
示例11: __init__
def __init__(self, *args, **kwargs):
super(PickleType, self).__init__(*args, **kwargs)
self.pack_bytes = marshal.packer_for('BytesType')
self.unpack_bytes = marshal.unpacker_for('BytesType')
示例12: __init__
def __init__(self, *args, **kwargs):
super(MicrosecondTimestampType, self).__init__(*args, **kwargs)
self.pack_integer = marshal.packer_for('IntegerType')
self.unpack_integer = marshal.unpacker_for('IntegerType')
示例13: __init__
def __init__(self, *args, **kwargs):
super(RealType, self).__init__(*args, **kwargs)
self.pack_ascii = marshal.packer_for('AsciiType')
self.unpack_ascii = marshal.unpacker_for('AsciiType')