<s> import os <EOL> import hashlib <EOL> from io import BytesIO <EOL> from tests . utils import driver <EOL> from onitu_webdav . wd import get_WEBDAV_client , create_dirs <EOL> from onitu . utils import get_random_string , b , dirname <EOL> class Driver ( driver . Driver ) : <EOL> def __init__ ( self , * args , ** options ) : <EOL> options [ '<STR_LIT>' ] = os . getenv ( <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ) <EOL> options [ '<STR_LIT:username>' ] = os . getenv ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> options [ '<STR_LIT:password>' ] = os . getenv ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> options [ '<STR_LIT>' ] = os . getenv ( "<STR_LIT>" , <NUM_LIT:5> ) <EOL> root = os . getenv ( "<STR_LIT>" , u"<STR_LIT:/>" ) <EOL> self . _root = root + get_random_string ( <NUM_LIT:10> ) <EOL> hostname = options [ '<STR_LIT>' ] <EOL> username = options [ '<STR_LIT:username>' ] <EOL> password = options [ '<STR_LIT:password>' ] <EOL> super ( Driver , self ) . __init__ ( '<STR_LIT>' , * args , ** options ) <EOL> self . webd = get_WEBDAV_client ( hostname , username , password ) <EOL> create_dirs ( self . webd , self . _root ) <EOL> @ property <EOL> def root ( self ) : <EOL> return self . _root <EOL> def close ( self ) : <EOL> self . rmdir ( self . root ) <EOL> def mkdir ( self , subdirs ) : <EOL> create_dirs ( self . webd , subdirs ) <EOL> def rmdir ( self , path ) : <EOL> self . webd . clean ( b ( path ) ) <EOL> def write ( self , filename , content ) : <EOL> create_dirs ( self . webd , dirname ( filename ) ) <EOL> buff = BytesIO ( content ) <EOL> self . webd . upload_from ( buff , b ( filename ) ) <EOL> def generate ( self , filename , size ) : <EOL> self . write ( filename , os . urandom ( size ) ) <EOL> def exists ( self , filename ) : <EOL> try : <EOL> self . webd . info ( b ( filename ) ) <EOL> except : <EOL> return False <EOL> return True <EOL> def unlink ( self , filename ) : <EOL> self . webd . clean ( b ( filename ) ) <EOL> def rename ( self , source , target ) : <EOL> self . webd . move ( remote_path_from = b ( source ) , remote_path_to = b ( target ) ) <EOL> def checksum ( self , filename ) : <EOL> buff = BytesIO ( ) <EOL> self . webd . download_to ( buff , b ( filename ) ) <EOL> data = buff . getvalue ( ) <EOL> md5 = hashlib . md5 ( data ) . hexdigest ( ) <EOL> return md5 <EOL> class DriverFeatures ( driver . DriverFeatures ) : <EOL> move_file_to_onitu = False </s>
