google.appengine.api.files.file module

Summary

Files API.

Deprecated since version 1.8.1: Use Google Cloud Storage Client library instead.

Contents

exception google.appengine.api.files.file.ApiTemporaryUnavailableErrorsource

Bases: google.appengine.api.files.file.Error

Files API is temporary unavailable. Request should be retried soon.

exception google.appengine.api.files.file.Errorsource

Bases: exceptions.Exception

Base error class for this module.

exception google.appengine.api.files.file.ExclusiveLockFailedErrorsource

Bases: google.appengine.api.files.file.Error

Exclusive lock can’t be obtained.

exception google.appengine.api.files.file.ExistenceErrorsource

Bases: google.appengine.api.files.file.Error

File is in wrong existence state.

exception google.appengine.api.files.file.FileNotOpenedErrorsource

Bases: google.appengine.api.files.file.Error

File was not opened.

exception google.appengine.api.files.file.FileTemporaryUnavailableErrorsource

Bases: google.appengine.api.files.file.Error

File is temporary unavailable. Request should be retried soon.

exception google.appengine.api.files.file.FinalizationErrorsource

Bases: google.appengine.api.files.file.Error

File is in wrong finalization state.

exception google.appengine.api.files.file.InvalidArgumentErrorsource

Bases: google.appengine.api.files.file.Error

Function argument has invalid value.

exception google.appengine.api.files.file.InvalidFileNameErrorsource

Bases: google.appengine.api.files.file.Error

File name is invalid.

exception google.appengine.api.files.file.InvalidParameterErrorsource

Bases: google.appengine.api.files.file.Error

Parameter specified in Create() call is invalid.

exception google.appengine.api.files.file.OperationNotSupportedErrorsource

Bases: google.appengine.api.files.file.Error

Incorrect file open mode.

exception google.appengine.api.files.file.PermissionDeniedErrorsource

Bases: google.appengine.api.files.file.Error

Application doesn’t have permissions to perform the operation.

exception google.appengine.api.files.file.ReadOnlyErrorsource

Bases: google.appengine.api.files.file.Error

File is read-only mode.

exception google.appengine.api.files.file.SequenceKeyOutOfOrderError(last_sequence_key, cause=None)source

Bases: google.appengine.api.files.file.Error

Sequence key specified is out of order.

last_sequence_key

last sequence key which was written to the file.

exception google.appengine.api.files.file.UnknownErrorsource

Bases: google.appengine.api.files.file.Error

Unknown unexpected io error occured.

exception google.appengine.api.files.file.UnsupportedContentTypeErrorsource

Bases: google.appengine.api.files.file.Error

Specified file content type is not supported by this api.

exception google.appengine.api.files.file.UnsupportedOpenModeErrorsource

Bases: google.appengine.api.files.file.Error

Unsupported file open mode was specified.

exception google.appengine.api.files.file.WrongContentTypeErrorsource

Bases: google.appengine.api.files.file.Error

File has a different content type.

exception google.appengine.api.files.file.WrongOpenModeErrorsource

Bases: google.appengine.api.files.file.Error

Incorrect file open mode.

google.appengine.api.files.file.delete(*filenames)source

Permanently delete files.

Delete on non-finalized/non-existent files is a no-op.

Parameters

filenames – finalized file names as strings. filename should has format “/gs/bucket/filename” or “/blobstore/blobkey”.

Raises
  • InvalidFileNameError – Raised when any filename is not of valid format or not a finalized name.

  • IOError – Raised if any problem occurs contacting the backend system.

google.appengine.api.files.file.finalize(filename, content_type=0)source

Finalize a file.

Parameters
  • filename – File name as string.

  • content_type – File’s content type. Value from FileContentType.ContentType enum.

google.appengine.api.files.file.listdir(path, **kwargs)source

Return a sorted list of filenames (matching a pattern) in the given path.

Only Google Cloud Storage paths are supported in current implementation.

Parameters
  • path – a Google Cloud Storage path of “/gs/bucketname” form.

  • kwargs – other keyword arguments to be relayed to Google Cloud Storage. This can be used to select certain files with names matching a pattern. See google.appengine.api.files.gs.listdir for details.

Returns

a list containing filenames (matching a pattern) from the given path. Sorted by Python String.

google.appengine.api.files.file.open(filename, mode='r', content_type=0, exclusive_lock=False, buffering=0)source

Open a file.

Parameters
  • filename – A name of the file as string.

  • mode – File open mode. Either ‘a’ or ‘r’.

  • content_type – File’s content type. Value from FileContentType.ContentType enum.

  • exclusive_lock – If file should be exclusively locked. All other exclusive lock attempts will file until file is correctly closed.

  • buffering – optional argument similar to the one in Python’s open. It specifies the file’s desired buffer size: 0 means unbuffered, positive value means use a buffer of that size, any negative value means the default size. Only read buffering is supported.

Returns

File object.

Raises

InvalidArgumentError – Raised when given illegal argument value or type.

google.appengine.api.files.file.stat(filename)source

Get status of a finalized file given it’s full path filename.

Returns

a _FileStat object similar to that returned by python’s os.stat(path).

Throws:

FinalizationError if file is not finalized.

class google.appengine.api.files.file.BufferedFile(filename, buffer_size=524288)source

Bases: object

BufferedFile is a file-like object reading underlying file in chunks.

close()source
read(size=None)source

Read data from RAW file.

Parameters

size – Number of bytes to read as integer. Actual number of bytes read is always equal to size unless end if file was reached.

Returns

A string with data read.

readline(size=-1)source

Read one line delimited by ‘ ‘ from the file.

A trailing newline character is kept in the string. It may be absent when a file ends with an incomplete line. If the size argument is non-negative, it specifies the maximum string size (counting the newline) to return. An empty string is returned only when EOF is encountered immediately.

Args:
size: Maximum number of bytes to read. If not specified, readline stops

only on ‘

‘ or EOF.

Returns:

The data read as a string.

seek(offset, whence=0)source

Set the file’s current position.

Parameters
  • offset – seek offset as number.

  • whence – seek mode. Supported modes are os.SEEK_SET (absolute seek), os.SEEK_CUR (seek relative to the current position), and os.SEEK_END (seek relative to the end, offset should be negative).

tell()source

Return file’s current position.