App Engine Python SDK version 1.8.1
[gae.git] / python / google / appengine / api / images / images_blob_stub.py
bloba32905a73bbb9382ddbf41753712e250eedc4090
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 """Stub version of the blob-related parts of the images API."""
29 import logging
31 from google.appengine.api import datastore
37 BLOB_SERVING_URL_KIND = "__BlobServingUrl__"
40 class ImagesBlobStub(object):
41 """Stub version of the blob-related parts of the images API."""
43 def __init__(self, host_prefix):
44 """Stub implementation of blob-related parts of the images API.
46 Args:
47 host_prefix: the URL prefix (protocol://host:port) to preprend to
48 image urls on a call to GetUrlBase.
49 """
50 self._host_prefix = host_prefix
52 def GetUrlBase(self, request, response):
53 """Trivial implementation of ImagesService::GetUrlBase.
55 Args:
56 request: ImagesGetUrlBaseRequest, contains a blobkey to an image
57 response: ImagesGetUrlBaseResponse, contains a url to serve the image
58 """
59 if request.create_secure_url():
60 logging.info("Secure URLs will not be created using the development "
61 "application server.")
63 entity_info = datastore.Entity(BLOB_SERVING_URL_KIND,
64 name=request.blob_key(),
65 namespace="")
66 entity_info["blob_key"] = request.blob_key()
67 datastore.Put(entity_info)
69 response.set_url("%s/_ah/img/%s" % (self._host_prefix, request.blob_key()))
71 def DeleteUrlBase(self, request, response):
72 """Trivial implementation of ImagesService::DeleteUrlBase.
74 Args:
75 request: ImagesDeleteUrlBaseRequest, contains a blobkey to an image.
76 response: ImagesDeleteUrlBaseResonse - currently unused.
77 """
78 key = datastore.Key.from_path(BLOB_SERVING_URL_KIND,
79 request.blob_key(),
80 namespace="")
81 datastore.Delete(key)