google.appengine.ext.bulkload.bulkload_deprecated module
Summary
DEPRECATED mix-in handler for bulk loading data into an application.
Please use the new bulkloader.
Contents
- class google.appengine.ext.bulkload.bulkload_deprecated.BulkLoadsource
-
Bases: google.appengine.ext.webapp._webapp25.RequestHandler
A handler for bulk load requests.
This class contains handlers for the bulkloading process. One for GET to provide cookie information for the upload script, and one handler for a POST request to upload the entities.
In the POST request, the body contains the data representing the entities’ property values. The original format was a sequences of lines of comma-separated values (and is handled by the Load method). The current (version 1) format is a binary format described in the Tools and Libraries section of the documentation, and is handled by the LoadV1 method).
- InfoPage(uri)source
Renders an information page with the POST endpoint and cookie flag.
Parametersuri – a string containing the request URI
ReturnsA string with the contents of the info page to be displayed
- IterRows(reader)source
Yields a tuple of a line number and row for each row of the CSV data.
Parametersreader – a csv reader for the input data.
- Load(kind, data)source
Parses CSV data, uses a Loader to convert to entities, and stores them.
On error, fails fast. Returns a “bad request” HTTP response code and includes the traceback in the output.
Parameters-
kind – a string containing the entity kind that this loader handles
-
data – a string containing the CSV data to load
response code: integer HTTP response code to return output: string containing the HTTP response body
Return typetuple (response code, output) where
-
- LoadEntities(iter, loader, key_format=None)source
Generates entities and loads them into the datastore. Returns a tuple of HTTP code and string reply.
Parameters-
iter – an iterator yielding pairs of a line number and row contents.
-
key_format – a format string to convert a line number into an entity id. If None, then entity ID’s are automatically generated.
-
- get()source
-
Handle a GET. Just show an info page.
- post()source
-
Handle a POST. Reads CSV data, converts to entities, and stores them.
- class google.appengine.ext.bulkload.bulkload_deprecated.Loader(kind, properties)source
-
Bases: object
A base class for creating datastore entities from input data.
To add a handler for bulk loading a new entity kind into your datastore, write a subclass of this class that calls Loader.__init__ from your class’s __init__.
If you need to run extra code to convert entities from the input data, create new properties, or otherwise modify the entities before they’re inserted, override HandleEntity.
See the CreateEntity method for the creation of entities from the (parsed) input data.
- CreateEntity(values, key_name=None)source
Creates an entity from a list of property values.
Parameters-
values – list/tuple of str
-
key_name – if provided, the name for the (single) resulting Entity
list of datastore.Entity
The returned entities are populated with the property values from the argument, converted to native types using the properties map given in the constructor, and passed through HandleEntity. They’re ready to be inserted.
RaisesAssertionError if the number of values doesn’t match the number – of properties in the properties map.
-
- HandleEntity(entity)source
Subclasses can override this to add custom entity conversion code.
This is called for each entity, after its properties are populated from CSV but before it is stored. Subclasses can override this to add custom entity handling code.
The entity to be inserted should be returned. If multiple entities should be inserted, return a list of entities. If no entities should be inserted, return None or [].
Parametersentity – datastore.Entity
Returnsdatastore.Entity or list of datastore.Entity
- static RegisteredLoaders()source
-
Returns a list of the Loader instances that have been created.
- kind()source
-
Return the entity kind that this Loader handes.
- google.appengine.ext.bulkload.bulkload_deprecated.Validate(value, type)source
Checks that value is non-empty and of the right type.
Raises ValueError if value is None or empty, TypeError if it’s not the given type.
Parameters-
value – any value
-
type – a type or tuple of types
-
- google.appengine.ext.bulkload.bulkload_deprecated.main(*loaders)source
Starts bulk upload.
Raises TypeError if not, at least one Loader instance is given.
Parametersloaders – One or more Loader instance.