<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import re <EOL> import sys <EOL> import time <EOL> import base64 <EOL> import random <EOL> import string <EOL> import textwrap <EOL> import functools <EOL> from . import utils <EOL> from . utils import minisix <EOL> from . version import version <EOL> from . i18n import PluginInternationalization <EOL> _ = PluginInternationalization ( ) <EOL> def debug ( s , * args ) : <EOL> """<STR_LIT>""" <EOL> print ( '<STR_LIT>' , s % args ) <EOL> userHostmaskRe = re . compile ( r'<STR_LIT>' ) <EOL> def isUserHostmask ( s ) : <EOL> """<STR_LIT>""" <EOL> return userHostmaskRe . match ( s ) is not None <EOL> def isServerHostmask ( s ) : <EOL> """<STR_LIT>""" <EOL> return not isUserHostmask ( s ) <EOL> def nickFromHostmask ( hostmask ) : <EOL> """<STR_LIT>""" <EOL> assert isUserHostmask ( hostmask ) <EOL> return splitHostmask ( hostmask ) [ <NUM_LIT:0> ] <EOL> def userFromHostmask ( hostmask ) : <EOL> """<STR_LIT>""" <EOL> assert isUserHostmask ( hostmask ) <EOL> return splitHostmask ( hostmask ) [ <NUM_LIT:1> ] <EOL> def hostFromHostmask ( hostmask ) : <EOL> """<STR_LIT>""" <EOL> assert isUserHostmask ( hostmask ) <EOL> return splitHostmask ( hostmask ) [ <NUM_LIT:2> ] <EOL> def splitHostmask ( hostmask ) : <EOL> """<STR_LIT>""" <EOL> assert isUserHostmask ( hostmask ) <EOL> nick , rest = hostmask . split ( '<STR_LIT:!>' , <NUM_LIT:1> ) <EOL> user , host = rest . split ( '<STR_LIT:@>' , <NUM_LIT:1> ) <EOL> return ( minisix . intern ( nick ) , minisix . intern ( user ) , minisix . intern ( host ) ) <EOL> def joinHostmask ( nick , ident , host ) : <EOL> """<STR_LIT>""" <EOL> assert nick and ident and host <EOL> return minisix . intern ( '<STR_LIT>' % ( nick , ident , host ) ) <EOL> _rfc1459trans = utils . str . MultipleReplacer ( dict ( list ( zip ( <EOL> string . ascii_uppercase + r'<STR_LIT>' , <EOL> string . ascii_lowercase + r'<STR_LIT>' ) ) ) ) <EOL> def toLower ( s , casemapping = None ) : <EOL> """<STR_LIT>""" <EOL> if casemapping is None or casemapping == '<STR_LIT>' : <EOL> return _rfc1459trans ( s ) <EOL> elif casemapping == '<STR_LIT:ascii>' : <EOL> return s . lower ( ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % casemapping ) <EOL> def strEqual ( nick1 , nick2 ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( nick1 , minisix . string_types ) <EOL> assert isinstance ( nick2 , minisix . string_types ) <EOL> return toLower ( nick1 ) == toLower ( nick2 ) <EOL> nickEqual = strEqual <EOL> _nickchars = r'<STR_LIT>' <EOL> nickRe = re . compile ( r'<STR_LIT>' <EOL> % ( re . escape ( _nickchars ) , re . escape ( _nickchars ) ) ) <EOL> def isNick ( s , strictRfc = True , nicklen = None ) : <EOL> """<STR_LIT>""" <EOL> if strictRfc : <EOL> ret = bool ( nickRe . match ( s ) ) <EOL> if ret and nicklen is not None : <EOL> ret = len ( s ) <= nicklen <EOL> return ret <EOL> else : <EOL> return not isChannel ( s ) and not isUserHostmask ( s ) and not '<STR_LIT:U+0020>' in s and not '<STR_LIT:!>' in s <EOL> def areNicks ( s , strictRfc = True , nicklen = None ) : <EOL> """<STR_LIT>""" <EOL> nick = functools . partial ( isNick , strictRfc = strictRfc , nicklen = nicklen ) <EOL> return all ( map ( nick , s . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> def isChannel ( s , chantypes = '<STR_LIT>' , channellen = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> return s and '<STR_LIT:U+002C>' not in s and '<STR_LIT>' not in s and s [ <NUM_LIT:0> ] in chantypes and len ( s ) <= channellen and len ( s . split ( None , <NUM_LIT:1> ) ) == <NUM_LIT:1> <EOL> def areChannels ( s , chantypes = '<STR_LIT>' , channellen = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> chan = functools . partial ( isChannel , chantypes = chantypes , <EOL> channellen = channellen ) <EOL> return all ( map ( chan , s . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> def areReceivers ( s , strictRfc = True , nicklen = None , chantypes = '<STR_LIT>' , <EOL> channellen = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> nick = functools . partial ( isNick , strictRfc = strictRfc , nicklen = nicklen ) <EOL> chan = functools . partial ( isChannel , chantypes = chantypes , <EOL> channellen = channellen ) <EOL> return all ( [ nick ( x ) or chan ( x ) for x in s . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> _patternCache = utils . structures . CacheDict ( <NUM_LIT:1000> ) <EOL> def _hostmaskPatternEqual ( pattern , hostmask ) : <EOL> try : <EOL> return _patternCache [ pattern ] ( hostmask ) is not None <EOL> except KeyError : <EOL> fd = minisix . io . StringIO ( ) <EOL> for c in pattern : <EOL> if c == '<STR_LIT:*>' : <EOL> fd . write ( '<STR_LIT>' ) <EOL> elif c == '<STR_LIT:?>' : <EOL> fd . write ( '<STR_LIT:.>' ) <EOL> elif c in '<STR_LIT>' : <EOL> fd . write ( '<STR_LIT>' ) <EOL> elif c in '<STR_LIT>' : <EOL> fd . write ( r'<STR_LIT>' ) <EOL> elif c in '<STR_LIT>' : <EOL> fd . write ( r'<STR_LIT>' ) <EOL> elif c in '<STR_LIT>' : <EOL> fd . write ( '<STR_LIT>' ) <EOL> else : <EOL> fd . write ( re . escape ( c ) ) <EOL> fd . write ( '<STR_LIT:$>' ) <EOL> f = re . compile ( fd . getvalue ( ) , re . I ) . match <EOL> _patternCache [ pattern ] = f <EOL> return f ( hostmask ) is not None <EOL> _hostmaskPatternEqualCache = utils . structures . CacheDict ( <NUM_LIT:1000> ) <EOL> def hostmaskPatternEqual ( pattern , hostmask ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return _hostmaskPatternEqualCache [ ( pattern , hostmask ) ] <EOL> except KeyError : <EOL> b = _hostmaskPatternEqual ( pattern , hostmask ) <EOL> _hostmaskPatternEqualCache [ ( pattern , hostmask ) ] = b <EOL> return b <EOL> def banmask ( hostmask ) : <EOL> """<STR_LIT>""" <EOL> assert isUserHostmask ( hostmask ) <EOL> host = hostFromHostmask ( hostmask ) <EOL> if utils . net . isIPV4 ( host ) : <EOL> L = host . split ( '<STR_LIT:.>' ) <EOL> L [ - <NUM_LIT:1> ] = '<STR_LIT:*>' <EOL> return '<STR_LIT>' + '<STR_LIT:.>' . join ( L ) <EOL> elif utils . net . isIPV6 ( host ) : <EOL> L = host . split ( '<STR_LIT::>' ) <EOL> L [ - <NUM_LIT:1> ] = '<STR_LIT:*>' <EOL> return '<STR_LIT>' + '<STR_LIT::>' . join ( L ) <EOL> else : <EOL> if len ( host . split ( '<STR_LIT:.>' ) ) > <NUM_LIT:2> : <EOL> return '<STR_LIT>' % host [ host . find ( '<STR_LIT:.>' ) : ] <EOL> else : <EOL> return '<STR_LIT>' + host <EOL> _plusRequireArguments = '<STR_LIT>' <EOL> _minusRequireArguments = '<STR_LIT>' <EOL> def separateModes ( args ) : <EOL> """<STR_LIT>""" <EOL> if not args : <EOL> return [ ] <EOL> modes = args [ <NUM_LIT:0> ] <EOL> assert modes [ <NUM_LIT:0> ] in '<STR_LIT>' , '<STR_LIT>' % args <EOL> args = list ( args [ <NUM_LIT:1> : ] ) <EOL> ret = [ ] <EOL> for c in modes : <EOL> if c in '<STR_LIT>' : <EOL> last = c <EOL> else : <EOL> if last == '<STR_LIT:+>' : <EOL> requireArguments = _plusRequireArguments <EOL> else : <EOL> requireArguments = _minusRequireArguments <EOL> if c in requireArguments : <EOL> if not args : <EOL> continue <EOL> arg = args . pop ( <NUM_LIT:0> ) <EOL> try : <EOL> arg = int ( arg ) <EOL> except ValueError : <EOL> pass <EOL> ret . append ( ( last + c , arg ) ) <EOL> else : <EOL> ret . append ( ( last + c , None ) ) <EOL> return ret <EOL> def joinModes ( modes ) : <EOL> """<STR_LIT>""" <EOL> args = [ ] <EOL> modeChars = [ ] <EOL> currentMode = '<STR_LIT:\x00>' <EOL> for ( mode , arg ) in modes : <EOL> if arg is not None : <EOL> args . append ( arg ) <EOL> if not mode . startswith ( currentMode ) : <EOL> currentMode = mode [ <NUM_LIT:0> ] <EOL> modeChars . append ( mode [ <NUM_LIT:0> ] ) <EOL> modeChars . append ( mode [ <NUM_LIT:1> ] ) <EOL> args . insert ( <NUM_LIT:0> , '<STR_LIT>' . join ( modeChars ) ) <EOL> return args <EOL> def bold ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % s <EOL> def italic ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % s <EOL> def reverse ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % s <EOL> def underline ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % s <EOL> def mircColor ( s , fg = None , bg = None ) : <EOL> """<STR_LIT>""" <EOL> if fg is None and bg is None : <EOL> return s <EOL> elif bg is None : <EOL> if str ( fg ) in mircColors : <EOL> fg = mircColors [ str ( fg ) ] <EOL> elif len ( str ( fg ) ) > <NUM_LIT:1> : <EOL> fg = mircColors [ str ( fg ) [ : - <NUM_LIT:1> ] ] <EOL> else : <EOL> pass <EOL> return '<STR_LIT>' % ( fg . zfill ( <NUM_LIT:2> ) , s ) <EOL> elif fg is None : <EOL> bg = mircColors [ str ( bg ) ] <EOL> return '<STR_LIT>' % ( bg . zfill ( <NUM_LIT:2> ) , s ) <EOL> else : <EOL> fg = mircColors [ str ( fg ) ] <EOL> bg = mircColors [ str ( bg ) ] <EOL> return '<STR_LIT>' % ( fg , bg . zfill ( <NUM_LIT:2> ) , s ) <EOL> def canonicalColor ( s , bg = False , shift = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> h = hash ( s ) >> shift <EOL> fg = h % <NUM_LIT> + <NUM_LIT:2> <EOL> if bg : <EOL> bg = ( h >> <NUM_LIT:4> ) & <NUM_LIT:3> <EOL> if fg < <NUM_LIT:8> : <EOL> bg += <NUM_LIT:8> <EOL> else : <EOL> bg += <NUM_LIT:2> <EOL> return ( fg , bg ) <EOL> else : <EOL> return ( fg , None ) <EOL> def stripBold ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def stripItalic ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _stripColorRe = re . compile ( r'<STR_LIT>' ) <EOL> def stripColor ( s ) : <EOL> """<STR_LIT>""" <EOL> return _stripColorRe . sub ( '<STR_LIT>' , s ) <EOL> def stripReverse ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def stripUnderline ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def stripFormatting ( s ) : <EOL> """<STR_LIT>""" <EOL> s = stripColor ( s ) <EOL> s = stripBold ( s ) <EOL> s = stripReverse ( s ) <EOL> s = stripUnderline ( s ) <EOL> s = stripItalic ( s ) <EOL> return s . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _containsFormattingRe = re . compile ( r'<STR_LIT>' ) <EOL> def formatWhois ( irc , replies , caller = '<STR_LIT>' , channel = '<STR_LIT>' , command = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> hostmask = '<STR_LIT:@>' . join ( replies [ '<STR_LIT>' ] . args [ <NUM_LIT:2> : <NUM_LIT:4> ] ) <EOL> nick = replies [ '<STR_LIT>' ] . args [ <NUM_LIT:1> ] <EOL> user = replies [ '<STR_LIT>' ] . args [ - <NUM_LIT:1> ] <EOL> START_CODE = '<STR_LIT>' if command == '<STR_LIT>' else '<STR_LIT>' <EOL> hostmask = '<STR_LIT:@>' . join ( replies [ START_CODE ] . args [ <NUM_LIT:2> : <NUM_LIT:4> ] ) <EOL> user = replies [ START_CODE ] . args [ - <NUM_LIT:1> ] <EOL> if _containsFormattingRe . search ( user ) and user [ - <NUM_LIT:1> ] != '<STR_LIT>' : <EOL> user = '<STR_LIT>' % user <EOL> if '<STR_LIT>' in replies : <EOL> channels = [ ] <EOL> for msg in replies [ '<STR_LIT>' ] : <EOL> channels . extend ( msg . args [ - <NUM_LIT:1> ] . split ( ) ) <EOL> ops = [ ] <EOL> voices = [ ] <EOL> normal = [ ] <EOL> halfops = [ ] <EOL> for chan in channels : <EOL> origchan = chan <EOL> chan = chan . lstrip ( '<STR_LIT>' ) <EOL> testchan = chan . lstrip ( '<STR_LIT:&>' ) <EOL> if testchan != chan and irc . isChannel ( testchan ) : <EOL> chan = testchan <EOL> diff = len ( chan ) - len ( origchan ) <EOL> modes = origchan [ : diff ] <EOL> chanState = irc . state . channels . get ( chan ) <EOL> if chanState : <EOL> if caller not in chanState . users : <EOL> continue <EOL> if set ( ( '<STR_LIT:p>' , '<STR_LIT:s>' ) ) & set ( chanState . modes . keys ( ) ) and not strEqual ( channel or '<STR_LIT>' , chan ) : <EOL> continue <EOL> if not modes : <EOL> normal . append ( chan ) <EOL> elif utils . iter . any ( lambda c : c in modes , ( '<STR_LIT:@>' , '<STR_LIT:&>' , '<STR_LIT>' , '<STR_LIT:!>' ) ) : <EOL> ops . append ( chan ) <EOL> elif utils . iter . any ( lambda c : c in modes , ( '<STR_LIT:%>' , ) ) : <EOL> halfops . append ( chan ) <EOL> elif utils . iter . any ( lambda c : c in modes , ( '<STR_LIT:+>' , ) ) : <EOL> voices . append ( chan ) <EOL> L = [ ] <EOL> if ops : <EOL> L . append ( format ( _ ( '<STR_LIT>' ) , ops ) ) <EOL> if halfops : <EOL> L . append ( format ( _ ( '<STR_LIT>' ) , halfops ) ) <EOL> if voices : <EOL> L . append ( format ( _ ( '<STR_LIT>' ) , voices ) ) <EOL> if normal : <EOL> if L : <EOL> L . append ( format ( _ ( '<STR_LIT>' ) , normal ) ) <EOL> else : <EOL> L . append ( format ( _ ( '<STR_LIT>' ) , normal ) ) <EOL> else : <EOL> if command == '<STR_LIT>' : <EOL> L = [ _ ( '<STR_LIT>' ) ] <EOL> else : <EOL> L = [ ] <EOL> channels = format ( '<STR_LIT>' , L ) <EOL> if '<STR_LIT>' in replies : <EOL> idle = utils . timeElapsed ( replies [ '<STR_LIT>' ] . args [ <NUM_LIT:2> ] ) <EOL> signon = utils . str . timestamp ( float ( replies [ '<STR_LIT>' ] . args [ <NUM_LIT:3> ] ) ) <EOL> else : <EOL> idle = '<STR_LIT>' <EOL> signon = '<STR_LIT>' <EOL> if '<STR_LIT>' in replies : <EOL> server = replies [ '<STR_LIT>' ] . args [ <NUM_LIT:2> ] <EOL> if len ( replies [ '<STR_LIT>' ] ) > <NUM_LIT:3> : <EOL> signoff = replies [ '<STR_LIT>' ] . args [ <NUM_LIT:3> ] <EOL> else : <EOL> server = '<STR_LIT>' <EOL> if '<STR_LIT>' in replies : <EOL> away = '<STR_LIT>' % ( nick , replies [ '<STR_LIT>' ] . args [ <NUM_LIT:2> ] ) <EOL> else : <EOL> away = '<STR_LIT>' <EOL> if '<STR_LIT>' in replies : <EOL> if replies [ '<STR_LIT>' ] . args [ <NUM_LIT:2> ] : <EOL> identify = '<STR_LIT>' <EOL> else : <EOL> identify = '<STR_LIT>' <EOL> else : <EOL> identify = '<STR_LIT>' <EOL> if command == '<STR_LIT>' : <EOL> s = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( user , hostmask , identify , server , <EOL> signon , idle , nick , channels , away ) <EOL> else : <EOL> s = _ ( '<STR_LIT>' ) % ( user , hostmask , identify , server , signoff ) <EOL> return s <EOL> class FormatContext ( object ) : <EOL> def __init__ ( self ) : <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> self . fg = None <EOL> self . bg = None <EOL> self . bold = False <EOL> self . reverse = False <EOL> self . underline = False <EOL> def start ( self , s ) : <EOL> """<STR_LIT>""" <EOL> if self . bold : <EOL> s = '<STR_LIT>' + s <EOL> if self . reverse : <EOL> s = '<STR_LIT>' + s <EOL> if self . underline : <EOL> s = '<STR_LIT>' + s <EOL> if self . fg is not None or self . bg is not None : <EOL> s = mircColor ( s , fg = self . fg , bg = self . bg ) [ : - <NUM_LIT:1> ] <EOL> return s <EOL> def end ( self , s ) : <EOL> """<STR_LIT>""" <EOL> if self . bold or self . reverse or self . fg or self . bg or self . underline : <EOL> s += '<STR_LIT>' <EOL> return s <EOL> class FormatParser ( object ) : <EOL> def __init__ ( self , s ) : <EOL> self . fd = minisix . io . StringIO ( s ) <EOL> self . last = None <EOL> def getChar ( self ) : <EOL> if self . last is not None : <EOL> c = self . last <EOL> self . last = None <EOL> return c <EOL> else : <EOL> return self . fd . read ( <NUM_LIT:1> ) <EOL> def ungetChar ( self , c ) : <EOL> self . last = c <EOL> def parse ( self ) : <EOL> context = FormatContext ( ) <EOL> c = self . getChar ( ) <EOL> while c : <EOL> if c == '<STR_LIT>' : <EOL> context . bold = not context . bold <EOL> elif c == '<STR_LIT>' : <EOL> context . reverse = not context . reverse <EOL> elif c == '<STR_LIT>' : <EOL> context . underline = not context . underline <EOL> elif c == '<STR_LIT>' : <EOL> context . reset ( ) <EOL> elif c == '<STR_LIT>' : <EOL> self . getColor ( context ) <EOL> c = self . getChar ( ) <EOL> return context <EOL> def getInt ( self ) : <EOL> i = <NUM_LIT:0> <EOL> setI = False <EOL> c = self . getChar ( ) <EOL> while c . isdigit ( ) : <EOL> j = i * <NUM_LIT:10> <EOL> j += int ( c ) <EOL> if j >= <NUM_LIT:16> : <EOL> self . ungetChar ( c ) <EOL> break <EOL> else : <EOL> setI = True <EOL> i = j <EOL> c = self . getChar ( ) <EOL> self . ungetChar ( c ) <EOL> if setI : <EOL> return i <EOL> else : <EOL> return None <EOL> def getColor ( self , context ) : <EOL> context . fg = self . getInt ( ) <EOL> c = self . getChar ( ) <EOL> if c == '<STR_LIT:U+002C>' : <EOL> context . bg = self . getInt ( ) <EOL> else : <EOL> self . ungetChar ( c ) <EOL> def wrap ( s , length , break_on_hyphens = False , break_long_words = False ) : <EOL> processed = [ ] <EOL> wrapper = textwrap . TextWrapper ( width = length ) <EOL> wrapper . break_long_words = break_long_words <EOL> wrapper . break_on_hyphens = break_on_hyphens <EOL> chunks = wrapper . wrap ( s ) <EOL> context = None <EOL> for chunk in chunks : <EOL> if context is not None : <EOL> chunk = context . start ( chunk ) <EOL> context = FormatParser ( chunk ) . parse ( ) <EOL> processed . append ( context . end ( chunk ) ) <EOL> return processed <EOL> def isValidArgument ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:\r>' not in s and '<STR_LIT:\n>' not in s and '<STR_LIT:\x00>' not in s <EOL> def safeArgument ( s ) : <EOL> """<STR_LIT>""" <EOL> if minisix . PY2 and isinstance ( s , unicode ) : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> elif ( minisix . PY2 and not isinstance ( s , minisix . string_types ) ) or ( minisix . PY3 and not isinstance ( s , str ) ) : <EOL> debug ( '<STR_LIT>' , s ) <EOL> s = str ( s ) <EOL> if isValidArgument ( s ) : <EOL> return s <EOL> else : <EOL> return repr ( s ) <EOL> def replyTo ( msg ) : <EOL> """<STR_LIT>""" <EOL> if isChannel ( msg . args [ <NUM_LIT:0> ] ) : <EOL> return msg . args [ <NUM_LIT:0> ] <EOL> else : <EOL> return msg . nick <EOL> def dccIP ( ip ) : <EOL> """<STR_LIT>""" <EOL> assert utils . net . isIPV4 ( ip ) , '<STR_LIT>' <EOL> i = <NUM_LIT:0> <EOL> x = <NUM_LIT> ** <NUM_LIT:3> <EOL> for quad in ip . split ( '<STR_LIT:.>' ) : <EOL> i += int ( quad ) * x <EOL> x //= <NUM_LIT> <EOL> return i <EOL> def unDccIP ( i ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( i , minisix . integer_types ) , '<STR_LIT>' % i <EOL> L = [ ] <EOL> while len ( L ) < <NUM_LIT:4> : <EOL> L . append ( i % <NUM_LIT> ) <EOL> i //= <NUM_LIT> <EOL> L . reverse ( ) <EOL> return '<STR_LIT:.>' . join ( map ( str , L ) ) <EOL> class IrcString ( str ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , s = '<STR_LIT>' ) : <EOL> x = super ( IrcString , cls ) . __new__ ( cls , s ) <EOL> x . lowered = str ( toLower ( x ) ) <EOL> return x <EOL> def __eq__ ( self , s ) : <EOL> try : <EOL> return toLower ( s ) == self . lowered <EOL> except : <EOL> return False <EOL> def __ne__ ( self , s ) : <EOL> return not ( self == s ) <EOL> def __hash__ ( self ) : <EOL> return hash ( self . lowered ) <EOL> class IrcDict ( utils . InsensitivePreservingDict ) : <EOL> """<STR_LIT>""" <EOL> def key ( self , s ) : <EOL> if s is not None : <EOL> s = toLower ( s ) <EOL> return s <EOL> class CallableValueIrcDict ( IrcDict ) : <EOL> def __getitem__ ( self , k ) : <EOL> v = super ( IrcDict , self ) . __getitem__ ( k ) <EOL> if callable ( v ) : <EOL> v = v ( ) <EOL> return v <EOL> class IrcSet ( utils . NormalizingSet ) : <EOL> """<STR_LIT>""" <EOL> def normalize ( self , s ) : <EOL> return IrcString ( s ) <EOL> def __reduce__ ( self ) : <EOL> return ( self . __class__ , ( list ( self ) , ) ) <EOL> class FloodQueue ( object ) : <EOL> timeout = <NUM_LIT:0> <EOL> def __init__ ( self , timeout = None , queues = None ) : <EOL> if timeout is not None : <EOL> self . timeout = timeout <EOL> if queues is None : <EOL> queues = IrcDict ( ) <EOL> self . queues = queues <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . timeout , <EOL> repr ( self . queues ) ) <EOL> def key ( self , msg ) : <EOL> return msg . host <EOL> def getTimeout ( self ) : <EOL> if callable ( self . timeout ) : <EOL> return self . timeout ( ) <EOL> else : <EOL> return self . timeout <EOL> def _getQueue ( self , msg , insert = True ) : <EOL> key = self . key ( msg ) <EOL> try : <EOL> return self . queues [ key ] <EOL> except KeyError : <EOL> if insert : <EOL> getTimeout = lambda : self . getTimeout ( ) <EOL> q = utils . structures . TimeoutQueue ( getTimeout ) <EOL> self . queues [ key ] = q <EOL> return q <EOL> else : <EOL> return None <EOL> def enqueue ( self , msg , what = None ) : <EOL> if what is None : <EOL> what = msg <EOL> q = self . _getQueue ( msg ) <EOL> q . enqueue ( what ) <EOL> def len ( self , msg ) : <EOL> q = self . _getQueue ( msg , insert = False ) <EOL> if q is not None : <EOL> return len ( q ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def has ( self , msg , what = None ) : <EOL> q = self . _getQueue ( msg , insert = False ) <EOL> if q is not None : <EOL> if what is None : <EOL> what = msg <EOL> for elt in q : <EOL> if elt == what : <EOL> return True <EOL> return False <EOL> mircColors = IrcDict ( { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> for ( k , v ) in list ( mircColors . items ( ) ) : <EOL> if k is not None : <EOL> sv = str ( v ) <EOL> mircColors [ sv ] = sv <EOL> mircColors [ sv . zfill ( <NUM_LIT:2> ) ] = sv <EOL> def standardSubstitute ( irc , msg , text , env = None ) : <EOL> """<STR_LIT>""" <EOL> def randInt ( ) : <EOL> return str ( random . randint ( - <NUM_LIT:1000> , <NUM_LIT:1000> ) ) <EOL> def randDate ( ) : <EOL> t = pow ( <NUM_LIT:2> , <NUM_LIT:30> ) * random . random ( ) + time . time ( ) / <NUM_LIT> <EOL> return time . ctime ( t ) <EOL> ctime = time . strftime ( "<STR_LIT>" ) <EOL> localtime = time . localtime ( ) <EOL> gmtime = time . strftime ( "<STR_LIT>" , time . gmtime ( ) ) <EOL> vars = CallableValueIrcDict ( { <EOL> '<STR_LIT>' : ctime , '<STR_LIT>' : ctime , <EOL> '<STR_LIT>' : gmtime , '<STR_LIT>' : gmtime , <EOL> '<STR_LIT>' : randDate , '<STR_LIT>' : randDate , <EOL> '<STR_LIT>' : randInt , '<STR_LIT>' : randInt , '<STR_LIT>' : randInt , <EOL> '<STR_LIT>' : time . strftime ( '<STR_LIT>' , localtime ) , <EOL> '<STR_LIT>' : localtime [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : localtime [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : time . strftime ( '<STR_LIT>' , localtime ) , <EOL> '<STR_LIT:date>' : localtime [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : time . strftime ( '<STR_LIT>' , localtime ) , <EOL> '<STR_LIT:h>' : localtime [ <NUM_LIT:3> ] , '<STR_LIT>' : localtime [ <NUM_LIT:3> ] , '<STR_LIT>' : localtime [ <NUM_LIT:3> ] , <EOL> '<STR_LIT:m>' : localtime [ <NUM_LIT:4> ] , '<STR_LIT>' : localtime [ <NUM_LIT:4> ] , '<STR_LIT>' : localtime [ <NUM_LIT:4> ] , <EOL> '<STR_LIT:s>' : localtime [ <NUM_LIT:5> ] , '<STR_LIT>' : localtime [ <NUM_LIT:5> ] , '<STR_LIT>' : localtime [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : time . strftime ( '<STR_LIT>' , localtime ) , <EOL> '<STR_LIT:version>' : '<STR_LIT>' % version , <EOL> } ) <EOL> if irc : <EOL> vars . update ( { <EOL> '<STR_LIT>' : irc . nick , <EOL> '<STR_LIT>' : irc . network , <EOL> } ) <EOL> if msg : <EOL> vars . update ( { <EOL> '<STR_LIT>' : msg . nick , <EOL> '<STR_LIT>' : msg . nick , <EOL> '<STR_LIT:user>' : msg . user , <EOL> '<STR_LIT:host>' : msg . host , <EOL> } ) <EOL> if msg . reply_env : <EOL> vars . update ( msg . reply_env ) <EOL> if irc and msg : <EOL> if isChannel ( msg . args [ <NUM_LIT:0> ] ) : <EOL> channel = msg . args [ <NUM_LIT:0> ] <EOL> else : <EOL> channel = '<STR_LIT>' <EOL> def randNick ( ) : <EOL> if channel != '<STR_LIT>' : <EOL> L = list ( irc . state . channels [ channel ] . users ) <EOL> if len ( L ) > <NUM_LIT:1> : <EOL> n = msg . nick <EOL> while n == msg . nick : <EOL> n = utils . iter . choice ( L ) <EOL> return n <EOL> else : <EOL> return msg . nick <EOL> else : <EOL> return '<STR_LIT>' <EOL> vars . update ( { <EOL> '<STR_LIT>' : randNick , '<STR_LIT>' : randNick , <EOL> '<STR_LIT>' : channel , <EOL> } ) <EOL> else : <EOL> vars . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> if env is not None : <EOL> vars . update ( env ) <EOL> t = string . Template ( text ) <EOL> t . idpattern = '<STR_LIT>' <EOL> return t . safe_substitute ( vars ) <EOL> AUTHENTICATE_CHUNK_SIZE = <NUM_LIT> <EOL> def authenticate_generator ( authstring , base64ify = True ) : <EOL> if base64ify : <EOL> authstring = base64 . b64encode ( authstring ) <EOL> if minisix . PY3 : <EOL> authstring = authstring . decode ( ) <EOL> for n in range ( <NUM_LIT:0> , len ( authstring ) + <NUM_LIT:1> , AUTHENTICATE_CHUNK_SIZE ) : <EOL> chunk = authstring [ n : n + AUTHENTICATE_CHUNK_SIZE ] or '<STR_LIT:+>' <EOL> yield chunk <EOL> class AuthenticateDecoder ( object ) : <EOL> def __init__ ( self ) : <EOL> self . chunks = [ ] <EOL> self . ready = False <EOL> def feed ( self , msg ) : <EOL> assert msg . command == '<STR_LIT>' <EOL> chunk = msg . args [ <NUM_LIT:0> ] <EOL> if chunk == '<STR_LIT:+>' or len ( chunk ) != AUTHENTICATE_CHUNK_SIZE : <EOL> self . ready = True <EOL> if chunk != '<STR_LIT:+>' : <EOL> if minisix . PY3 : <EOL> chunk = chunk . encode ( ) <EOL> self . chunks . append ( chunk ) <EOL> def get ( self ) : <EOL> assert self . ready <EOL> return base64 . b64decode ( b'<STR_LIT>' . join ( self . chunks ) ) <EOL> numerics = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import doctest <EOL> doctest . testmod ( sys . modules [ '<STR_LIT:__main__>' ] ) </s>
