<s> from django . conf import settings <EOL> from ws4redis . redis_store import RedisStore , SELF <EOL> class RedisSubscriber ( RedisStore ) : <EOL> """<STR_LIT>""" <EOL> subscription_channels = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> publish_channels = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , connection ) : <EOL> self . _subscription = None <EOL> super ( RedisSubscriber , self ) . __init__ ( connection ) <EOL> def parse_response ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _subscription . parse_response ( ) <EOL> def set_pubsub_channels ( self , request , channels ) : <EOL> """<STR_LIT>""" <EOL> facility = request . path_info . replace ( settings . WEBSOCKET_URL , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> audience = { <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels , <EOL> } <EOL> self . _publishers = set ( ) <EOL> for key in self . _get_message_channels ( request = request , facility = facility , ** audience ) : <EOL> self . _publishers . add ( key ) <EOL> audience = { <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels and [ SELF ] or [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' in channels , <EOL> } <EOL> self . _subscription = self . _connection . pubsub ( ) <EOL> for key in self . _get_message_channels ( request = request , facility = facility , ** audience ) : <EOL> self . _subscription . subscribe ( key ) <EOL> def send_persited_messages ( self , websocket ) : <EOL> """<STR_LIT>""" <EOL> for channel in self . _subscription . channels : <EOL> message = self . _connection . get ( channel ) <EOL> if message : <EOL> websocket . send ( message ) <EOL> def get_file_descriptor ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _subscription . connection and self . _subscription . connection . _sock . fileno ( ) <EOL> def release ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _subscription and self . _subscription . subscribed : <EOL> self . _subscription . unsubscribe ( ) <EOL> self . _subscription . reset ( ) </s>
