Changeset 2720 in products for quintagroup.transmogrifier
- Timestamp:
- Aug 4, 2010 11:49:56 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier/branches/dictionary/quintagroup/transmogrifier/namespaces/atns.py
r2719 r2720 17 17 from quintagroup.transmogrifier.namespaces.util import has_ctrlchars 18 18 19 #######################################20 # Setup logging system #21 #######################################22 import logging23 DEFAULT_LOG = "/tmp/quintagroup.transmogrifier.log"24 FORMAT = "[%(asctime)s]: %(message)s"25 #FORMAT = "[%H:%M:%S]: %(message)s"26 def createHandler(hndlr_cls, level, *args, **kwargs):27 hndlr = hndlr_cls(*args, **kwargs)28 hndlr.setLevel(level)29 hndlr.setFormatter(logging.Formatter(FORMAT, datefmt="%H:%M:%S"))30 return hndlr31 32 # Very IMPORTANT create logger as logging.Logger NOT logging.getLogger !!!33 logger = logging.Logger("Quintagroup Transmogrifier", logging.NOTSET)34 logger.addHandler(createHandler(35 logging.FileHandler, logging.DEBUG, DEFAULT_LOG))36 37 #######################################38 39 19 _marker = () 40 41 20 42 21 class ATAttribute(base.ATAttribute): … … 55 34 56 35 def addNode(node, value, nspref): 57 # Create text node and add *value* to the *node*.58 # Use *nspref* if needed.59 36 if is_ref: 60 37 if config.HANDLE_REFS: … … 81 58 return 82 59 83 # if self.name in ['payablesMap', 'fieldMap']:84 # import ipdb;ipdb.set_trace()85 86 60 is_ref = self.isReference(instance) 87 61 … … 95 69 items = getattr(value, 'items', _marker) 96 70 if items is not _marker and callable(items): 71 # Map field 97 72 # set type attribute for the field 98 73 type_attr = dom.createAttribute("type") … … 112 87 node.appendChild(item_node) 113 88 else: 89 # Common field 114 90 value = getPreparedValue(value) 115 91 addNode(node, value, self.namespace.xmlns) … … 121 97 122 98 def processXmlValue(self, context, value): 123 if value is None: 124 return 99 def getValue(node, value): 100 if value is None: 101 return 102 value = value.strip() 103 if not value: 104 return 105 # decode node value if needed 106 te = node.get('transfer_encoding', None) 107 if te is not None: 108 value = value.decode(te) 109 return value 110 111 # Get value type 112 vtype = context.node.attrib.get('type', None) 113 if vtype=='dict': 114 # process dictionary type 115 d = {} 116 for item in context.node: 117 k = item.get("key", None) 118 v = getValue(item, item.text) 119 if k and v: 120 d[k] = v 121 value = d 122 else: 123 # Common field 124 value = getValue(context.node, value) 125 125 126 value = value.strip()127 126 if not value: 128 127 return 129 130 # decode node value if needed131 te = context.node.get('transfer_encoding', None)132 if te is not None:133 value = value.decode(te)134 # process dictionary type135 vtype = context.node.attrib.get('type', None)136 if vtype and vtype=='dict':137 try:138 s = value.strip("{}\t\n")139 # value = dict([map(lambda x:x.strip(" '\""), item.split("': '")) \140 # for item in s.split("', '")])141 value = dict([map(lambda x:x.strip(" '\""), item.split(": ")) \142 for item in s.split(", ")])143 except:144 #import ipdb;ipdb.set_trace()145 logger.error("Error on processing '%s' dict type field,\n"\146 " for object: '%s'\n " \147 " for the following data: '%s'" % (str(context.instance.id),148 context.instance.absolute_url(), str(value)))149 150 128 151 129 data = context.getDataFor(self.namespace.xmlns)
Note: See TracChangeset
for help on using the changeset viewer.