<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import gzip <EOL> import logging <EOL> import logging . handlers <EOL> import os <EOL> import shutil <EOL> _LG = logging <EOL> class CompressedRotatingFileHandler ( _LG . handlers . RotatingFileHandler ) : <EOL> def rotate_existing_files ( self ) : <EOL> for i in range ( self . backupCount - <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> source = '<STR_LIT>' . format ( <EOL> filename = self . baseFilename , extension = i ) <EOL> dest = '<STR_LIT>' . format ( <EOL> filename = self . baseFilename , extension = i + <NUM_LIT:1> ) <EOL> if os . path . exists ( source ) : <EOL> if os . path . exists ( dest ) : <EOL> os . remove ( dest ) <EOL> os . rename ( source , dest ) <EOL> dest = self . baseFilename + "<STR_LIT>" <EOL> if os . path . exists ( dest ) : <EOL> os . remove ( dest ) <EOL> def rotator ( self , source , dest ) : <EOL> with open ( source , '<STR_LIT:rb>' ) as f_in , gzip . open ( dest , '<STR_LIT:wb>' ) as f_out : <EOL> shutil . copyfileobj ( f_in , f_out ) <EOL> os . remove ( source ) <EOL> def doRollover ( self ) : <EOL> if self . stream : <EOL> self . stream . close ( ) <EOL> self . rotate_existing_files ( ) <EOL> self . rotator ( self . baseFilename , self . baseFilename + "<STR_LIT>" ) <EOL> self . mode = '<STR_LIT:w>' <EOL> self . stream = self . _open ( ) </s>
