<s> """<STR_LIT>""" <EOL> import struct <EOL> from thrift import Thrift <EOL> from thrift . transport import TSocket , TTransport <EOL> from thrift . protocol import TBinaryProtocol <EOL> from hbase import Hbase , ttypes <EOL> exceptions = ( Thrift . TException , ttypes . IOError , ttypes . IllegalArgument , <EOL> ttypes . AlreadyExists ) <EOL> def convert ( rows ) : <EOL> """<STR_LIT>""" <EOL> for row in rows : <EOL> columns = row . columns <EOL> for key , tcell in columns . iteritems ( ) : <EOL> columns [ key ] = struct . unpack ( '<STR_LIT>' , tcell . value ) [ <NUM_LIT:0> ] <EOL> return rows <EOL> class Client ( object ) : <EOL> def __init__ ( self , host , port , table ) : <EOL> self . host = host <EOL> self . port = port <EOL> self . table = table <EOL> self . open ( ) <EOL> def open ( self ) : <EOL> socket = TSocket . TSocket ( self . host , self . port ) <EOL> self . transport = TTransport . TBufferedTransport ( socket ) <EOL> protocol = TBinaryProtocol . TBinaryProtocol ( self . transport ) <EOL> self . client = Hbase . Client ( protocol ) <EOL> self . transport . open ( ) <EOL> def close ( self ) : <EOL> self . transport . close ( ) <EOL> def recycle ( self ) : <EOL> self . close ( ) <EOL> self . open ( ) <EOL> def __del__ ( self ) : <EOL> self . close ( ) <EOL> def scanner ( self , start = '<STR_LIT>' , columns = None ) : <EOL> """<STR_LIT>""" <EOL> id = self . client . scannerOpen ( self . table , start , columns ) <EOL> return Scanner ( self , id ) <EOL> def row ( self , row_ , columns = None ) : <EOL> """<STR_LIT>""" <EOL> rv = self . client . getRowWithColumns ( self . table , row_ , columns ) <EOL> return convert ( rv ) if rv else [ ] <EOL> class Scanner ( object ) : <EOL> def __init__ ( self , client , id ) : <EOL> self . client = client <EOL> self . id = id <EOL> def next ( self ) : <EOL> """<STR_LIT>""" <EOL> return convert ( self . client . client . scannerGet ( self . id ) ) [ <NUM_LIT:0> ] <EOL> def list ( self , num ) : <EOL> """<STR_LIT>""" <EOL> return convert ( self . client . client . scannerGetList ( self . id , num ) ) </s>
