Package ajango :: Package core :: Module hybrid
[hide private]
[frames] | no frames]

Source Code for Module ajango.core.hybrid

 1  ########################################################################### 
 2  #                                                                         # 
 3  #  Copyright (C) 2016  Rafal Kobel <rafyco1@gmail.com>                    # 
 4  #                                                                         # 
 5  #  This program is free software: you can redistribute it and/or modify   # 
 6  #  it under the terms of the GNU General Public License as published by   # 
 7  #  the Free Software Foundation, either version 3 of the License, or      # 
 8  #  (at your option) any later version.                                    # 
 9  #                                                                         # 
10  #  This program is distributed in the hope that it will be useful,        # 
11  #  but WITHOUT ANY WARRANTY; without even the implied warranty of         # 
12  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           # 
13  #  GNU General Public License for more details.                           # 
14  #                                                                         # 
15  #  You should have received a copy of the GNU General Public License      # 
16  #  along with this program.  If not, see <http://www.gnu.org/licenses/>.  # 
17  #                                                                         # 
18  ########################################################################### 
19  """ 
20  Modul z klasa abstrakcyjna dla obiektow ktore moga byc inicjalizowane zarowno 
21  przez dane XML jak i przez zmienna slowinkowa. 
22  """ 
23   
24  from django.core.management.base  import CommandError 
25  from ajango.core.XMLReader        import XMLReader 
26  from xml.dom                      import minidom 
27  import abc 
28 29 -def get_str_object_factory(obj, default='default'):
30 """ Zwraca okreslenie typu obiektu w postaci napisu. """ 31 if isinstance(obj.object, minidom.Element): 32 obj.str = obj.object.getAttribute('type') 33 if obj.str == "": 34 obj.str = default 35 obj.param = obj.object.getAttribute('param') 36 else: 37 try: 38 obj.str = obj.object['type'] 39 except KeyError: 40 raise CommandError("Input element is invalid")
41
42 -class Hybrid(XMLReader):
43 """ Klasa . """ 44 __metaclass__ = abc.ABCMeta
45 - def __init__(self, param):
46 self.object = param 47 if self.is_read_from_xmldoc(): 48 XMLReader.__init__(self, param, param) 49 else: 50 self.read_from_dict(param)
51 - def init(self):
52 """ Inicjalizacja obiektu. """ 53 self.read_from_xml(self.object)
54 @abc.abstractmethod
55 - def read_from_xml(self, xmldoc):
56 """ Inicjalizacja z danych XML. """ 57 raise NotImplementedError()
58 @abc.abstractmethod
59 - def read_from_dict(self, param):
60 """ Inicjalizacja ze zmiennej slownikowej. """ 61 raise NotImplementedError()
62 - def is_read_from_xmldoc(self):
63 """ Sparwdzanie czy obiekt jest odczytany z XML'a. """ 64 return isinstance(self.object, minidom.Element)
65