~ubuntu-branches/ubuntu/lucid/lazr.restfulclient/lucid-proposed

« back to all changes in this revision

Viewing changes to .pc/delay_resource_type_request.patch/src/lazr/restfulclient/tests/example.py

  • Committer: Bazaar Package Importer
  • Author(s): Brian Murray
  • Date: 2010-07-20 13:16:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100720131602-0wz5djkeuk8f3yyx
Tags: 0.9.11-1ubuntu1.1
* debian/patches/user-agent.patch: from upstream bzr revno 92 - send a real
  value for the user-agent header (LP: #607947)
* debian/patches/httplib2-workaround.patch: from upstream bzr revno 94 -
  workaround a bug in httplib2 (LP: #607947)
* debian/patches/user-agent.patch: from upstream bzr revno 99 - request
  compressed representation with Content-Encoding instead of TE
  (LP: #607947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009 Canonical Ltd.  All rights reserved.
 
2
#
 
3
# This file is part of lazr.restfulclient
 
4
#
 
5
# lazr.restfulclient is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU Lesser General Public License as published by
 
7
# the Free Software Foundation, version 3 of the License.
 
8
#
 
9
# lazr.restfulclient is distributed in the hope that it will be useful, but WITHOUT
 
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
12
# License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with lazr.restfulclient.  If not, see <http://www.gnu.org/licenses/>.
 
16
"Test client for the lazr.restful example web service."
 
17
 
 
18
__metaclass__ = type
 
19
__all__ = [
 
20
    'CookbookWebServiceClient',
 
21
    ]
 
22
 
 
23
from urllib import quote
 
24
 
 
25
from lazr.restfulclient.resource import (
 
26
    CollectionWithKeyBasedLookup, ServiceRoot)
 
27
 
 
28
 
 
29
class CookbookSet(CollectionWithKeyBasedLookup):
 
30
    """A custom subclass capable of cookbook lookup by cookbook name."""
 
31
 
 
32
    def _get_url_from_id(self, id):
 
33
        """Transform a cookbook name into the URL to a cookbook resource."""
 
34
        return (str(self._root._root_uri.ensureSlash())
 
35
                + 'cookbooks/' + quote(str(id)))
 
36
 
 
37
 
 
38
class RecipeSet(CollectionWithKeyBasedLookup):
 
39
    """A custom subclass capable of recipe lookup by recipe ID."""
 
40
 
 
41
    def _get_url_from_id(self, id):
 
42
        """Transform a recipe ID into the URL to a recipe resource."""
 
43
        return str(self._root._root_uri.ensureSlash()) + 'recipes/' + str(id)
 
44
 
 
45
 
 
46
class CookbookWebServiceClient(ServiceRoot):
 
47
 
 
48
    RESOURCE_TYPE_CLASSES = dict(ServiceRoot.RESOURCE_TYPE_CLASSES)
 
49
    RESOURCE_TYPE_CLASSES['recipes'] = RecipeSet
 
50
    RESOURCE_TYPE_CLASSES['cookbooks'] = CookbookSet
 
51
 
 
52
    DEFAULT_SERVICE_ROOT = "http://cookbooks.dev/"
 
53
    DEFAULT_VERSION = "1.0"
 
54
 
 
55
    def __init__(self, service_root=DEFAULT_SERVICE_ROOT,
 
56
                 version=DEFAULT_VERSION, cache=None):
 
57
        super(CookbookWebServiceClient, self).__init__(
 
58
            None, service_root, cache=cache, version=version)