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."""
30 from google
.appengine
.api
import datastore
33 BLOB_SERVING_URL_KIND
= '__BlobServingUrl__'
36 class ImagesBlobStub(object):
37 """Stub version of the blob-related parts of the images API."""
39 def __init__(self
, host_prefix
):
40 """Stub implementation of blob-related parts of the images API.
43 host_prefix: string - The URL prefix (protocol://host:port) to prepend to
44 image URLs on a call to GetUrlBase.
46 self
._host
_prefix
= host_prefix
48 def GetUrlBase(self
, request
, response
):
49 """Trivial implementation of an API call.
52 request: ImagesGetUrlBaseRequest - Contains a blobkey to an image.
53 response: ImagesGetUrlBaseResponse - Contains a URL to serve the image.
55 if request
.create_secure_url():
56 logging
.info('Secure URLs will not be created using the development '
57 'application server.')
59 entity_info
= datastore
.Entity(
60 BLOB_SERVING_URL_KIND
, name
=request
.blob_key(), namespace
='')
61 entity_info
['blob_key'] = request
.blob_key()
62 datastore
.Put(entity_info
)
64 response
.set_url('%s/_ah/img/%s' % (self
._host
_prefix
, request
.blob_key()))
66 def DeleteUrlBase(self
, request
, unused_response
):
67 """Trivial implementation of an API call.
70 request: ImagesDeleteUrlBaseRequest - Contains a blobkey to an image.
71 unused_response: ImagesDeleteUrlBaseResponse - Unused.
73 key
= datastore
.Key
.from_path(
74 BLOB_SERVING_URL_KIND
, request
.blob_key(), namespace
='')