source: mauRepo/CedaMarkup/trunk/ceda_markup/atom/info.py @ 8388

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/CedaMarkup/trunk/ceda_markup/atom/info.py@8388
Revision 8388, 3.5 KB checked in by mnagni, 7 years ago (diff)

Critical bug in Info need a further release

  • Property svn:mime-type set to text/plain
Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 25 May 2012
30
31@author: Maurizio Nagni
32'''
33from abc import abstractmethod
34from xml.etree.ElementTree import Element
35
36
37class Info(object):
38    '''
39    classdocs
40    '''
41    TEXT_TYPE = 'text'
42    HTML_TYPE = 'html'
43    XHTML_TYPE = 'xhtml'
44    TYPES = [TEXT_TYPE, HTML_TYPE, XHTML_TYPE]
45
46    def __init__(self, itype = TEXT_TYPE, body = ''):
47        '''
48        Constructor
49        '''
50        if itype in Info.TYPES:
51            self.type = itype
52        else:
53            raise Exception("Type is not allowed")
54        self.body = body
55
56    def buildElement(self):
57        info = self._buildRoot()
58        if self.type != Info.TEXT_TYPE:
59            info.set('type', self.type)
60        if self.type == Info.HTML_TYPE or self.type == Info.TEXT_TYPE:
61            info.text = self.body
62
63        if self.type == Info.XHTML_TYPE and isinstance(self.body, Element):
64            info.append(self.body)
65             
66        return info
67
68    @abstractmethod
69    def _buildRoot(self):
70        """
71            Build the Element root for this instance
72        """
73        pass       
74   
75class Title(Info):
76    '''
77    classdocs
78    '''
79
80    def __init__(self, type, body):
81        super(Title, self).__init__(type, body)
82       
83    def _buildRoot(self):
84        return Element('title')     
85   
86class Summary(Info):
87    '''
88    classdocs
89    '''
90
91    def __init__(self, type, body):
92        super(Summary, self).__init__(type, body)
93       
94    def _buildRoot(self):
95        return Element('summary')
96       
97class Content(Info):
98    '''
99    classdocs
100    '''
101
102    def __init__(self, type, body):
103        super(Content, self).__init__(type, body)
104       
105    def _buildRoot(self):
106        return Element('content')       
107   
108class Rights(Info):
109    '''
110    classdocs
111    '''
112
113    def __init__(self, type, body):
114        super(Rights, self).__init__(type, body)
115       
116    def _buildRoot(self):
117        return Element('rights')   
Note: See TracBrowser for help on using the repository browser.