#NEWLINE# def save( self , filename = None , ignore_discard = False , ignore_expires = False ) : #NEWLINE# #INDENT# if ( filename is None ) : #NEWLINE# #INDENT# if ( self . filename is not None ) : #NEWLINE# #INDENT# filename = self . filename #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( MISSING_FILENAME_TEXT ) #NEWLINE# #UNINDENT# #UNINDENT# f = open ( filename , 'w' ) #NEWLINE# try : #NEWLINE# #INDENT# debug ( 'Saving Netscape cookies.txt file' ) #NEWLINE# f . write ( self . header ) #NEWLINE# now = time . time ( ) #NEWLINE# for cookie in self : #NEWLINE# #INDENT# if ( ( not ignore_discard ) and cookie . discard ) : #NEWLINE# #INDENT# debug ( '   Not saving %s: marked for discard' , cookie . name ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( ( not ignore_expires ) and cookie . is_expired ( now ) ) : #NEWLINE# #INDENT# debug ( '   Not saving %s: expired' , cookie . name ) #NEWLINE# continue #NEWLINE# #UNINDENT# if cookie . secure : #NEWLINE# #INDENT# secure = 'TRUE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# secure = 'FALSE' #NEWLINE# #UNINDENT# if cookie . domain . startswith ( '.' ) : #NEWLINE# #INDENT# initial_dot = 'TRUE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# initial_dot = 'FALSE' #NEWLINE# #UNINDENT# if ( cookie . expires is not None ) : #NEWLINE# #INDENT# expires = str ( cookie . expires ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expires = '' #NEWLINE# #UNINDENT# if ( cookie . value is None ) : #NEWLINE# #INDENT# name = '' #NEWLINE# value = cookie . name #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# name = name . name #NEWLINE# value = cookie . value #NEWLINE# #UNINDENT# f . write ( ( '\t' . join ( [ cookie . domain , initial_dot , cookie . path , secure , expires , name , value ] ) + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( )