~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/logic/types/atom.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010-2011 OpenStack, LLC.
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License");
 
4
# you may not use this file except in compliance with the License.
 
5
# You may obtain a copy of the License at
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
from lxml import etree
 
16
 
 
17
 
 
18
class Link(object):
 
19
    """An atom link"""
 
20
 
 
21
    def __init__(self, rel, href, link_type=None, hreflang=None, title=None):
 
22
        self.rel = rel
 
23
        self.href = href
 
24
        self.link_type = link_type
 
25
        self.hreflang = hreflang
 
26
        self.title = title
 
27
 
 
28
    def to_dict(self):
 
29
        links = {}
 
30
        if self.link_type:
 
31
            links["link_type"] = self.link_type
 
32
        if self.hreflang:
 
33
            links["hreflang"] = self.hreflang
 
34
        if self.title:
 
35
            links["title"] = self.title
 
36
 
 
37
        links["rel"] = self.rel
 
38
        links["href"] = self.href
 
39
        return {'links': links}
 
40
 
 
41
    def to_dom(self):
 
42
        ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"
 
43
        ATOM = "{%s}" % ATOM_NAMESPACE
 
44
        NSMAP = {'atom': ATOM_NAMESPACE}
 
45
        dom = etree.Element(ATOM + "link", nsmap=NSMAP)
 
46
        if self.link_type:
 
47
            dom.set("link_type", self.link_type)
 
48
        if self.link_type:
 
49
            dom.set("hreflang", self.hreflang)
 
50
        if self.title:
 
51
            dom.set("title", self.title)
 
52
        dom.set("rel", self.rel)
 
53
        dom.set("href", self.href)
 
54
        return dom