<s> """<STR_LIT>""" <EOL> import calendar <EOL> from datetime import datetime <EOL> import pycassa . marshal as marshal <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class CassandraType ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , reversed = False , default = None ) : <EOL> self . reversed = reversed <EOL> self . default = default <EOL> if not hasattr ( self . __class__ , '<STR_LIT>' ) : <EOL> self . pack = marshal . packer_for ( self . __class__ . __name__ ) <EOL> if not hasattr ( self . __class__ , '<STR_LIT>' ) : <EOL> self . unpack = marshal . unpacker_for ( self . __class__ . __name__ ) <EOL> def __str__ ( self ) : <EOL> return self . __class__ . __name__ + "<STR_LIT>" + str ( self . reversed ) . lower ( ) + "<STR_LIT:)>" <EOL> class BytesType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class LongType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class IntegerType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Int32Type ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AsciiType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class UTF8Type ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class UUIDType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class TimeUUIDType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class LexicalUUIDType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CounterColumnType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DoubleType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class FloatType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DecimalType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class BooleanType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DateType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> TimestampType = DateType <EOL> def _to_timestamp ( v , use_micros = False ) : <EOL> if use_micros : <EOL> scale = <NUM_LIT> <EOL> micro_scale = <NUM_LIT:1.0> <EOL> else : <EOL> scale = <NUM_LIT> <EOL> micro_scale = <NUM_LIT> <EOL> try : <EOL> converted = calendar . timegm ( v . utctimetuple ( ) ) <EOL> converted = ( converted * scale ) + ( getattr ( v , '<STR_LIT>' , <NUM_LIT:0> ) / micro_scale ) <EOL> except AttributeError : <EOL> if type ( v ) not in marshal . _number_types : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> converted = v * scale <EOL> return long ( converted ) <EOL> class OldPycassaDateType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def pack ( v , * args , ** kwargs ) : <EOL> ts = _to_timestamp ( v , use_micros = True ) <EOL> return marshal . _long_packer . pack ( ts ) <EOL> @ staticmethod <EOL> def unpack ( v ) : <EOL> ts = marshal . _long_packer . unpack ( v ) [ <NUM_LIT:0> ] / <NUM_LIT> <EOL> return datetime . utcfromtimestamp ( ts ) <EOL> class IntermediateDateType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def pack ( v , * args , ** kwargs ) : <EOL> ts = _to_timestamp ( v , use_micros = False ) <EOL> return marshal . _long_packer . pack ( ts ) <EOL> @ staticmethod <EOL> def unpack ( v ) : <EOL> raw_ts = marshal . _long_packer . unpack ( v ) [ <NUM_LIT:0> ] / <NUM_LIT> <EOL> try : <EOL> return datetime . utcfromtimestamp ( raw_ts ) <EOL> except ValueError : <EOL> corrected_ts = raw_ts / <NUM_LIT> <EOL> return datetime . utcfromtimestamp ( corrected_ts ) <EOL> class CompositeType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * components ) : <EOL> self . components = components <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( map ( str , self . components ) ) + "<STR_LIT:)>" <EOL> @ property <EOL> def pack ( self ) : <EOL> return marshal . get_composite_packer ( composite_type = self ) <EOL> @ property <EOL> def unpack ( self ) : <EOL> return marshal . get_composite_unpacker ( composite_type = self ) <EOL> class DynamicCompositeType ( CassandraType ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * aliases ) : <EOL> self . aliases = { } <EOL> for alias in aliases : <EOL> if isinstance ( alias , dict ) : <EOL> self . aliases . update ( alias ) <EOL> def __str__ ( self ) : <EOL> aliases = [ ] <EOL> for k , v in self . aliases . iteritems ( ) : <EOL> aliases . append ( k + '<STR_LIT>' + str ( v ) ) <EOL> return "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( aliases ) + "<STR_LIT:)>" </s>
