<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import uuid <EOL> from slimta import logging <EOL> from . import QueueStorage <EOL> __all__ = [ '<STR_LIT>' ] <EOL> log = logging . getQueueStorageLogger ( __name__ ) <EOL> class DictStorage ( QueueStorage ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , envelope_db = None , meta_db = None ) : <EOL> super ( DictStorage , self ) . __init__ ( ) <EOL> self . env_db = envelope_db if envelope_db is not None else { } <EOL> self . meta_db = meta_db if meta_db is not None else { } <EOL> def write ( self , envelope , timestamp ) : <EOL> while True : <EOL> id = uuid . uuid4 ( ) . hex <EOL> if id not in self . env_db : <EOL> self . env_db [ id ] = envelope <EOL> self . meta_db [ id ] = { '<STR_LIT>' : timestamp , '<STR_LIT>' : <NUM_LIT:0> } <EOL> log . write ( id , envelope ) <EOL> return id <EOL> def set_timestamp ( self , id , timestamp ) : <EOL> meta = self . meta_db [ id ] <EOL> meta [ '<STR_LIT>' ] = timestamp <EOL> self . meta_db [ id ] = meta <EOL> log . update_meta ( id , timestamp = timestamp ) <EOL> def increment_attempts ( self , id ) : <EOL> meta = self . meta_db [ id ] <EOL> new_attempts = meta [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> meta [ '<STR_LIT>' ] = new_attempts <EOL> self . meta_db [ id ] = meta <EOL> log . update_meta ( id , attempts = new_attempts ) <EOL> return new_attempts <EOL> def set_recipients_delivered ( self , id , rcpt_indexes ) : <EOL> self . _remove_delivered_rcpts ( self . env_db [ id ] , rcpt_indexes ) <EOL> log . update_meta ( id , delivered_indexes = rcpt_indexes ) <EOL> def load ( self ) : <EOL> for key in self . meta_db . keys ( ) : <EOL> meta = self . meta_db [ key ] <EOL> yield ( meta [ '<STR_LIT>' ] , key ) <EOL> def get ( self , id ) : <EOL> meta = self . meta_db [ id ] <EOL> return self . env_db [ id ] , meta [ '<STR_LIT>' ] <EOL> def remove ( self , id ) : <EOL> try : <EOL> del self . meta_db [ id ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> del self . env_db [ id ] <EOL> except KeyError : <EOL> pass <EOL> log . remove ( id ) <EOL> def get_info ( self ) : <EOL> return { '<STR_LIT:size>' : len ( self . env_db ) , <EOL> '<STR_LIT>' : len ( self . meta_db ) } </s>
