<s> """<STR_LIT>""" <EOL> from builtins import object <EOL> from django . conf import settings <EOL> from django . utils import timezone <EOL> from django . db import models <EOL> from evennia . typeclasses . models import TypedObject <EOL> from evennia . typeclasses . tags import Tag , TagHandler <EOL> from evennia . utils . idmapper . models import SharedMemoryModel <EOL> from evennia . comms import managers <EOL> from evennia . locks . lockhandler import LockHandler <EOL> from evennia . utils . utils import crop , make_iter , lazy_property <EOL> __all__ = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> _GA = object . __getattribute__ <EOL> _SA = object . __setattr__ <EOL> _DA = object . __delattr__ <EOL> class Msg ( SharedMemoryModel ) : <EOL> """<STR_LIT>""" <EOL> db_sender_players = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , <EOL> null = True , verbose_name = '<STR_LIT>' , db_index = True ) <EOL> db_sender_objects = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , <EOL> null = True , verbose_name = '<STR_LIT>' , db_index = True ) <EOL> db_sender_external = models . CharField ( '<STR_LIT>' , max_length = <NUM_LIT:255> , null = True , db_index = True , <EOL> help_text = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> db_receivers_players = models . ManyToManyField ( '<STR_LIT>' , related_name = '<STR_LIT>' , <EOL> null = True , help_text = "<STR_LIT>" ) <EOL> db_receivers_objects = models . ManyToManyField ( '<STR_LIT>' , related_name = '<STR_LIT>' , <EOL> null = True , help_text = "<STR_LIT>" ) <EOL> db_receivers_channels = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , <EOL> null = True , help_text = "<STR_LIT>" ) <EOL> db_header = models . TextField ( '<STR_LIT>' , null = True , blank = True ) <EOL> db_message = models . TextField ( '<STR_LIT>' ) <EOL> db_date_sent = models . DateTimeField ( '<STR_LIT>' , editable = False , auto_now_add = True , db_index = True ) <EOL> db_lock_storage = models . TextField ( '<STR_LIT>' , blank = True , <EOL> help_text = '<STR_LIT>' ) <EOL> db_hide_from_players = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , null = True ) <EOL> db_hide_from_objects = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , null = True ) <EOL> db_hide_from_channels = models . ManyToManyField ( "<STR_LIT>" , related_name = '<STR_LIT>' , null = True ) <EOL> db_tags = models . ManyToManyField ( Tag , null = True , <EOL> help_text = '<STR_LIT>' ) <EOL> objects = managers . MsgManager ( ) <EOL> _is_deleted = False <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> SharedMemoryModel . __init__ ( self , * args , ** kwargs ) <EOL> self . extra_senders = [ ] <EOL> class Meta ( object ) : <EOL> "<STR_LIT>" <EOL> verbose_name = "<STR_LIT>" <EOL> @ lazy_property <EOL> def locks ( self ) : <EOL> return LockHandler ( self ) <EOL> @ lazy_property <EOL> def tags ( self ) : <EOL> return TagHandler ( self ) <EOL> def __senders_get ( self ) : <EOL> "<STR_LIT>" <EOL> return list ( self . db_sender_players . all ( ) ) + list ( self . db_sender_objects . all ( ) ) + self . extra_senders <EOL> def __senders_set ( self , senders ) : <EOL> "<STR_LIT>" <EOL> for sender in make_iter ( senders ) : <EOL> if not sender : <EOL> continue <EOL> if isinstance ( sender , basestring ) : <EOL> self . db_sender_external = sender <EOL> self . extra_senders . append ( sender ) <EOL> self . save ( update_fields = [ "<STR_LIT>" ] ) <EOL> continue <EOL> if not hasattr ( sender , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> clsname = sender . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . db_sender_objects . add ( sender ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_sender_players . add ( sender ) <EOL> def __senders_del ( self ) : <EOL> "<STR_LIT>" <EOL> self . db_sender_players . clear ( ) <EOL> self . db_sender_objects . clear ( ) <EOL> self . db_sender_external = "<STR_LIT>" <EOL> self . extra_senders = [ ] <EOL> self . save ( ) <EOL> senders = property ( __senders_get , __senders_set , __senders_del ) <EOL> def remove_sender ( self , senders ) : <EOL> """<STR_LIT>""" <EOL> for sender in make_iter ( senders ) : <EOL> if not sender : <EOL> continue <EOL> if isinstance ( sender , basestring ) : <EOL> self . db_sender_external = "<STR_LIT>" <EOL> self . save ( update_fields = [ "<STR_LIT>" ] ) <EOL> if not hasattr ( sender , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> clsname = sender . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . db_sender_objects . remove ( sender ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_sender_players . remove ( sender ) <EOL> def __receivers_get ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . db_receivers_players . all ( ) ) + list ( self . db_receivers_objects . all ( ) ) <EOL> def __receivers_set ( self , receivers ) : <EOL> """<STR_LIT>""" <EOL> for receiver in make_iter ( receivers ) : <EOL> if not receiver : <EOL> continue <EOL> if not hasattr ( receiver , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> clsname = receiver . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . db_receivers_objects . add ( receiver ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_receivers_players . add ( receiver ) <EOL> def __receivers_del ( self ) : <EOL> "<STR_LIT>" <EOL> self . db_receivers_players . clear ( ) <EOL> self . db_receivers_objects . clear ( ) <EOL> self . save ( ) <EOL> receivers = property ( __receivers_get , __receivers_set , __receivers_del ) <EOL> def remove_receiver ( self , receivers ) : <EOL> """<STR_LIT>""" <EOL> for receiver in make_iter ( receivers ) : <EOL> if not receiver : <EOL> continue <EOL> if not hasattr ( receiver , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> clsname = receiver . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . db_receivers_objects . remove ( receiver ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_receivers_players . remove ( receiver ) <EOL> def __channels_get ( self ) : <EOL> "<STR_LIT>" <EOL> return self . db_receivers_channels . all ( ) <EOL> def __channels_set ( self , value ) : <EOL> """<STR_LIT>""" <EOL> for val in ( v for v in make_iter ( value ) if v ) : <EOL> self . db_receivers_channels . add ( val ) <EOL> def __channels_del ( self ) : <EOL> "<STR_LIT>" <EOL> self . db_receivers_channels . clear ( ) <EOL> self . save ( ) <EOL> channels = property ( __channels_get , __channels_set , __channels_del ) <EOL> def __hide_from_get ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . db_hide_from_players . all ( ) , self . db_hide_from_objects . all ( ) , self . db_hide_from_channels . all ( ) <EOL> def __hide_from_set ( self , hiders ) : <EOL> "<STR_LIT>" <EOL> for hider in make_iter ( hiders ) : <EOL> if not hider : <EOL> continue <EOL> if not hasattr ( hider , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> clsname = hider . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . db_hide_from_players . add ( hider . __dbclass__ ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_hide_from_objects . add ( hider . __dbclass__ ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . db_hide_from_channels . add ( hider . __dbclass__ ) <EOL> def __hide_from_del ( self ) : <EOL> "<STR_LIT>" <EOL> self . db_hide_from_players . clear ( ) <EOL> self . db_hide_from_objects . clear ( ) <EOL> self . db_hide_from_channels . clear ( ) <EOL> self . save ( ) <EOL> hide_from = property ( __hide_from_get , __hide_from_set , __hide_from_del ) <EOL> def __str__ ( self ) : <EOL> "<STR_LIT>" <EOL> senders = "<STR_LIT:U+002C>" . join ( obj . key for obj in self . senders ) <EOL> receivers = "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % obj . key for obj in self . channels ] + [ obj . key for obj in self . receivers ] ) <EOL> return "<STR_LIT>" % ( senders , receivers , crop ( self . message , width = <NUM_LIT> ) ) <EOL> class TempMsg ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , senders = None , receivers = None , channels = None , message = "<STR_LIT>" , header = "<STR_LIT>" , type = "<STR_LIT>" , lockstring = "<STR_LIT>" , hide_from = None ) : <EOL> """<STR_LIT>""" <EOL> self . senders = senders and make_iter ( senders ) or [ ] <EOL> self . receivers = receivers and make_iter ( receivers ) or [ ] <EOL> self . channels = channels and make_iter ( channels ) or [ ] <EOL> self . type = type <EOL> self . header = header <EOL> self . message = message <EOL> self . lock_storage = lockstring <EOL> self . hide_from = hide_from and make_iter ( hide_from ) or [ ] <EOL> self . date_sent = timezone . now ( ) <EOL> @ lazy_property <EOL> def locks ( self ) : <EOL> return LockHandler ( self ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> senders = "<STR_LIT:U+002C>" . join ( obj . key for obj in self . senders ) <EOL> receivers = "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % obj . key for obj in self . channels ] + [ obj . key for obj in self . receivers ] ) <EOL> return "<STR_LIT>" % ( senders , receivers , crop ( self . message , width = <NUM_LIT> ) ) <EOL> def remove_sender ( self , sender ) : <EOL> """<STR_LIT>""" <EOL> for o in make_iter ( sender ) : <EOL> try : <EOL> self . senders . remove ( o ) <EOL> except ValueError : <EOL> pass <EOL> def remove_receiver ( self , receiver ) : <EOL> """<STR_LIT>""" <EOL> for o in make_iter ( receiver ) : <EOL> try : <EOL> self . senders . remove ( o ) <EOL> except ValueError : <EOL> pass <EOL> def access ( self , accessing_obj , access_type = '<STR_LIT>' , default = False ) : <EOL> """<STR_LIT>""" <EOL> return self . locks . check ( accessing_obj , <EOL> access_type = access_type , default = default ) <EOL> class SubscriptionHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> self . obj = obj <EOL> def has ( self , entity ) : <EOL> """<STR_LIT>""" <EOL> clsname = entity . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> return entity in self . obj . db_subscriptions . all ( ) <EOL> elif clsname == "<STR_LIT>" : <EOL> return entity in self . obj . db_object_subscriptions . all ( ) <EOL> def add ( self , entity ) : <EOL> """<STR_LIT>""" <EOL> for subscriber in make_iter ( entity ) : <EOL> if subscriber : <EOL> clsname = subscriber . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . obj . db_object_subscriptions . add ( subscriber ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . obj . db_subscriptions . add ( subscriber ) <EOL> def remove ( self , entity ) : <EOL> """<STR_LIT>""" <EOL> for subscriber in make_iter ( entity ) : <EOL> if subscriber : <EOL> clsname = subscriber . __dbclass__ . __name__ <EOL> if clsname == "<STR_LIT>" : <EOL> self . obj . db_subscriptions . remove ( entity ) <EOL> elif clsname == "<STR_LIT>" : <EOL> self . obj . db_object_subscriptions . remove ( entity ) <EOL> def all ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . obj . db_subscriptions . all ( ) ) + list ( self . obj . db_object_subscriptions . all ( ) ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . obj . db_subscriptions . clear ( ) <EOL> self . obj . db_object_subscriptions . clear ( ) <EOL> class ChannelDB ( TypedObject ) : <EOL> """<STR_LIT>""" <EOL> db_subscriptions = models . ManyToManyField ( "<STR_LIT>" , <EOL> related_name = "<STR_LIT>" , null = True , verbose_name = '<STR_LIT>' , db_index = True ) <EOL> db_object_subscriptions = models . ManyToManyField ( "<STR_LIT>" , <EOL> related_name = "<STR_LIT>" , null = True , verbose_name = '<STR_LIT>' , db_index = True ) <EOL> objects = managers . ChannelDBManager ( ) <EOL> __settingclasspath__ = settings . BASE_CHANNEL_TYPECLASS <EOL> __defaultclasspath__ = "<STR_LIT>" <EOL> __applabel__ = "<STR_LIT>" <EOL> class Meta ( object ) : <EOL> "<STR_LIT>" <EOL> verbose_name = "<STR_LIT>" <EOL> verbose_name_plural = "<STR_LIT>" <EOL> def __str__ ( self ) : <EOL> "<STR_LIT>" <EOL> return "<STR_LIT>" % ( self . key , self . db . desc ) <EOL> @ lazy_property <EOL> def subscriptions ( self ) : <EOL> return SubscriptionHandler ( self ) </s>
