#NEWLINE# def __init__( self , open_request , file_storage ) : #NEWLINE# #INDENT# 'Constructor.\n\n    Args:\n      open_request: An instance of open file request.\n      file_storage: An instance of BlobstoreStorage.\n    ' #NEWLINE# self . filename = open_request . filename ( ) #NEWLINE# self . file_storage = file_storage #NEWLINE# self . blob_reader = None #NEWLINE# self . content_type = None #NEWLINE# self . mime_content_type = None #NEWLINE# open_mode = open_request . open_mode ( ) #NEWLINE# content_type = open_request . content_type ( ) #NEWLINE# if ( not self . filename . startswith ( _BLOBSTORE_DIRECTORY ) ) : #NEWLINE# #INDENT# if ( not self . file_storage . has_blobstore_file ( self . filename ) ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . INVALID_FILE_NAME ) #NEWLINE# #UNINDENT# #UNINDENT# self . ticket = self . filename [ len ( _BLOBSTORE_DIRECTORY ) : ] #NEWLINE# if ( open_mode == file_service_pb . OpenRequest . APPEND ) : #NEWLINE# #INDENT# if ( not self . file_storage . has_blobstore_file ( self . filename ) ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . EXISTENCE_ERROR ) #NEWLINE# #UNINDENT# if self . file_storage . is_finalized ( self . filename ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . FINALIZATION_ERROR , 'File is already finalized' ) #NEWLINE# #UNINDENT# self . mime_content_type = self . file_storage . get_content_type ( self . filename ) #NEWLINE# self . blob_file_name = self . file_storage . get_blob_file_name ( self . filename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . ticket . startswith ( files . _CREATION_HANDLE_PREFIX ) : #NEWLINE# #INDENT# blobkey = self . file_storage . get_blob_key ( self . ticket ) #NEWLINE# if ( not blobkey ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . FINALIZATION_ERROR , 'Blobkey not found.' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# blobkey = content_type . ticket #NEWLINE# #UNINDENT# blob_info = blobstore . BlobInfo . get ( blobkey ) #NEWLINE# if ( not blob_info ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . FINALIZATION_ERROR , 'Blobinfo not found.' ) #NEWLINE# #UNINDENT# self . blob_reader = blobstore . BlobReader ( blob_info ) #NEWLINE# self . mime_content_type = blob_info . content_type #NEWLINE# #UNINDENT# if ( content_type != file_service_pb . FileContentType . RAW ) : #NEWLINE# #INDENT# raise_error ( file_service_pb . FileServiceErrors . WRONG_CONTENT_TYPE )