<s> """<STR_LIT>""" <EOL> import os <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from google . appengine . _internal . django . conf import settings <EOL> from google . appengine . _internal . django . core . files . base import File <EOL> from google . appengine . _internal . django . core . files import temp as tempfile <EOL> from google . appengine . _internal . django . utils . encoding import smart_str <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class UploadedFile ( File ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_CHUNK_SIZE = <NUM_LIT:64> * <NUM_LIT:2> ** <NUM_LIT:10> <EOL> def __init__ ( self , file = None , name = None , content_type = None , size = None , charset = None ) : <EOL> super ( UploadedFile , self ) . __init__ ( file , name ) <EOL> self . size = size <EOL> self . content_type = content_type <EOL> self . charset = charset <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . __class__ . __name__ , smart_str ( self . name ) , self . content_type ) <EOL> def _get_name ( self ) : <EOL> return self . _name <EOL> def _set_name ( self , name ) : <EOL> if name is not None : <EOL> name = os . path . basename ( name ) <EOL> if len ( name ) > <NUM_LIT:255> : <EOL> name , ext = os . path . splitext ( name ) <EOL> name = name [ : <NUM_LIT:255> - len ( ext ) ] + ext <EOL> self . _name = name <EOL> name = property ( _get_name , _set_name ) <EOL> class TemporaryUploadedFile ( UploadedFile ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , content_type , size , charset ) : <EOL> if settings . FILE_UPLOAD_TEMP_DIR : <EOL> file = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' , <EOL> dir = settings . FILE_UPLOAD_TEMP_DIR ) <EOL> else : <EOL> file = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' ) <EOL> super ( TemporaryUploadedFile , self ) . __init__ ( file , name , content_type , size , charset ) <EOL> def temporary_file_path ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . file . name <EOL> def close ( self ) : <EOL> try : <EOL> return self . file . close ( ) <EOL> except OSError , e : <EOL> if e . errno != <NUM_LIT:2> : <EOL> raise <EOL> class InMemoryUploadedFile ( UploadedFile ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file , field_name , name , content_type , size , charset ) : <EOL> super ( InMemoryUploadedFile , self ) . __init__ ( file , name , content_type , size , charset ) <EOL> self . field_name = field_name <EOL> def open ( self , mode = None ) : <EOL> self . file . seek ( <NUM_LIT:0> ) <EOL> def close ( self ) : <EOL> pass <EOL> def chunks ( self , chunk_size = None ) : <EOL> self . file . seek ( <NUM_LIT:0> ) <EOL> yield self . read ( ) <EOL> def multiple_chunks ( self , chunk_size = None ) : <EOL> return False <EOL> class SimpleUploadedFile ( InMemoryUploadedFile ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , content , content_type = '<STR_LIT>' ) : <EOL> content = content or '<STR_LIT>' <EOL> super ( SimpleUploadedFile , self ) . __init__ ( StringIO ( content ) , None , name , <EOL> content_type , len ( content ) , None ) <EOL> def from_dict ( cls , file_dict ) : <EOL> """<STR_LIT>""" <EOL> return cls ( file_dict [ '<STR_LIT:filename>' ] , <EOL> file_dict [ '<STR_LIT:content>' ] , <EOL> file_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> from_dict = classmethod ( from_dict ) </s>
