<s> from SipMsg import SipMsg <EOL> from SipHeader import SipHeader <EOL> from SipCSeq import SipCSeq <EOL> from SipTo import SipTo <EOL> from SipResponse import SipResponse <EOL> from SipURL import SipURL <EOL> from SipAddress import SipAddress <EOL> from SipExpires import SipExpires <EOL> class SipRequest ( SipMsg ) : <EOL> method = None <EOL> ruri = None <EOL> sipver = None <EOL> user_agent = None <EOL> def __init__ ( self , buf = None , method = None , ruri = None , sipver = '<STR_LIT>' , to = None , fr0m = None , via = None , cseq = None , callid = None , maxforwards = None , body = None , contact = None , routes = ( ) , target = None , cguid = None , <EOL> user_agent = None , expires = None ) : <EOL> SipMsg . __init__ ( self , buf ) <EOL> if buf != None : <EOL> return <EOL> self . method = method <EOL> self . ruri = ruri <EOL> if target == None : <EOL> if len ( routes ) == <NUM_LIT:0> : <EOL> self . setTarget ( self . ruri . getAddr ( ) ) <EOL> else : <EOL> self . setTarget ( routes [ <NUM_LIT:0> ] . getAddr ( ) ) <EOL> else : <EOL> self . setTarget ( target ) <EOL> self . sipver = sipver <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = via ) ) <EOL> if via == None : <EOL> self . getHFBody ( '<STR_LIT>' ) . genBranch ( ) <EOL> self . appendHeaders ( [ SipHeader ( name = '<STR_LIT>' , body = x ) for x in routes ] ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = maxforwards ) ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = fr0m ) ) <EOL> if to == None : <EOL> to = SipTo ( address = SipAddress ( url = ruri ) ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT:to>' , body = to ) ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = callid ) ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = SipCSeq ( cseq = cseq , method = method ) ) ) <EOL> if contact != None : <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = contact ) ) <EOL> if expires == None and method == '<STR_LIT>' : <EOL> expires = SipHeader ( name = '<STR_LIT>' ) <EOL> self . appendHeader ( expires ) <EOL> elif expires != None : <EOL> expires = SipHeader ( name = '<STR_LIT>' , body = expires ) <EOL> self . appendHeader ( expires ) <EOL> if user_agent != None : <EOL> self . user_agent = user_agent <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , bodys = user_agent ) ) <EOL> else : <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' ) ) <EOL> if cguid != None : <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = cguid ) ) <EOL> self . appendHeader ( SipHeader ( name = '<STR_LIT>' , body = cguid ) ) <EOL> if body != None : <EOL> self . setBody ( body ) <EOL> def setSL ( self , startline ) : <EOL> self . method , ruri , self . sipver = startline . split ( ) <EOL> self . ruri = SipURL ( ruri ) <EOL> def getSL ( self ) : <EOL> return self . method + '<STR_LIT:U+0020>' + str ( self . ruri ) + '<STR_LIT:U+0020>' + self . sipver <EOL> def getMethod ( self ) : <EOL> return self . method <EOL> def getRURI ( self ) : <EOL> return self . ruri <EOL> def setRURI ( self , ruri ) : <EOL> self . ruri = ruri <EOL> def genResponse ( self , scode , reason , body = None , server = None ) : <EOL> return SipResponse ( scode = scode , reason = reason , sipver = self . sipver , fr0m = self . getHFBCopy ( '<STR_LIT>' ) , callid = self . getHFBCopy ( '<STR_LIT>' ) , vias = self . getHFBCopys ( '<STR_LIT>' ) , to = self . getHFBCopy ( '<STR_LIT:to>' ) , cseq = self . getHFBCopy ( '<STR_LIT>' ) , rrs = self . getHFBCopys ( '<STR_LIT>' ) , body = body , server = server ) <EOL> def genACK ( self , to = None ) : <EOL> if to == None : <EOL> to = self . getHFBody ( '<STR_LIT:to>' ) . getCopy ( ) <EOL> maxforwards = self . getHFBodys ( '<STR_LIT>' ) <EOL> if len ( maxforwards ) > <NUM_LIT:0> : <EOL> maxforward = maxforwards [ <NUM_LIT:0> ] . getCopy ( ) <EOL> else : <EOL> maxforward = None <EOL> return SipRequest ( method = '<STR_LIT>' , ruri = self . ruri . getCopy ( ) , sipver = self . sipver , fr0m = self . getHFBCopy ( '<STR_LIT>' ) , to = to , via = self . getHFBCopy ( '<STR_LIT>' ) , callid = self . getHFBCopy ( '<STR_LIT>' ) , cseq = self . getHFBody ( '<STR_LIT>' ) . getCSeqNum ( ) , maxforwards = maxforward , user_agent = self . user_agent ) <EOL> def genCANCEL ( self ) : <EOL> maxforwards = self . getHFBodys ( '<STR_LIT>' ) <EOL> if len ( maxforwards ) > <NUM_LIT:0> : <EOL> maxforward = maxforwards [ <NUM_LIT:0> ] . getCopy ( ) <EOL> else : <EOL> maxforward = None <EOL> return SipRequest ( method = '<STR_LIT>' , ruri = self . ruri . getCopy ( ) , sipver = self . sipver , fr0m = self . getHFBCopy ( '<STR_LIT>' ) , to = self . getHFBCopy ( '<STR_LIT:to>' ) , via = self . getHFBCopy ( '<STR_LIT>' ) , callid = self . getHFBCopy ( '<STR_LIT>' ) , cseq = self . getHFBody ( '<STR_LIT>' ) . getCSeqNum ( ) , maxforwards = maxforward , routes = self . getHFBCopys ( '<STR_LIT>' ) , target = self . getTarget ( ) , user_agent = self . user_agent ) <EOL> def genRequest ( self , method , cseq = None ) : <EOL> if cseq == None : <EOL> cseq = self . getHFBody ( '<STR_LIT>' ) . getCSeqNum ( ) <EOL> maxforwards = self . getHFBodys ( '<STR_LIT>' ) <EOL> if len ( maxforwards ) > <NUM_LIT:0> : <EOL> maxforward = maxforwards [ <NUM_LIT:0> ] . getCopy ( ) <EOL> else : <EOL> maxforward = None <EOL> expires = self . getHFBodys ( '<STR_LIT>' ) <EOL> if len ( expires ) > <NUM_LIT:0> : <EOL> expires = expires [ <NUM_LIT:0> ] . getCopy ( ) <EOL> else : <EOL> expires = None <EOL> return SipRequest ( method = method , ruri = self . ruri . getCopy ( ) , sipver = self . sipver , fr0m = self . getHFBCopy ( '<STR_LIT>' ) , to = self . getHFBCopy ( '<STR_LIT:to>' ) , via = self . getHFBCopy ( '<STR_LIT>' ) , callid = self . getHFBCopy ( '<STR_LIT>' ) , cseq = cseq , maxforwards = maxforward , user_agent = self . user_agent , expires = expires ) </s>
