<s> from StringIO import StringIO <EOL> from muntjac . api import VerticalLayout , Label <EOL> from muntjac . ui . upload import Upload , IReceiver , IFinishedListener <EOL> class UploadBasicExample ( VerticalLayout ) : <EOL> def __init__ ( self ) : <EOL> super ( UploadBasicExample , self ) . __init__ ( ) <EOL> self . _result = Label ( ) <EOL> self . _counter = LineBreakCounter ( ) <EOL> self . _upload = Upload ( '<STR_LIT>' , self . _counter ) <EOL> self . addComponent ( self . _upload ) <EOL> self . addComponent ( self . _result ) <EOL> self . _upload . addListener ( FinishedListener ( self ) , IFinishedListener ) <EOL> class FinishedListener ( IFinishedListener ) : <EOL> def __init__ ( self , c ) : <EOL> self . _c = c <EOL> def uploadFinished ( self , event ) : <EOL> self . _c . _result . setValue ( '<STR_LIT>' <EOL> + self . _c . _counter . getLineBreakCount ( ) + '<STR_LIT>' ) <EOL> class LineBreakCounter ( IReceiver ) : <EOL> def __init__ ( self ) : <EOL> self . _fileName = None <EOL> self . _mtype = None <EOL> self . _counter = None <EOL> def receiveUpload ( self , filename , MIMEType ) : <EOL> """<STR_LIT>""" <EOL> self . _counter = <NUM_LIT:0> <EOL> self . _fileName = filename <EOL> self . _mtype = MIMEType <EOL> return OutputStream ( self ) <EOL> def getFileName ( self ) : <EOL> return self . _fileName <EOL> def getMimeType ( self ) : <EOL> return self . _mtype <EOL> def getLineBreakCount ( self ) : <EOL> return self . _counter <EOL> class OutputStream ( StringIO ) : <EOL> def __init__ ( self , lbc ) : <EOL> super ( OutputStream , self ) . __init__ ( ) <EOL> self . _lbc = lbc <EOL> def write ( self , b ) : <EOL> if b == '<STR_LIT:\n>' : <EOL> self . _lbc . _counter += <NUM_LIT:1> </s>
