Changeset 1414 in products


Ignore:
Timestamp:
Nov 26, 2009 11:05:20 AM (14 years ago)
Author:
piv
Message:

merge plone2.1 branche updates (r2426-2428,2433-2452): manifests with valid xml now, binary files fully dumped, local roles are imported, control characters are handled properly

Location:
quintagroup.transmogrifier/trunk
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.transmogrifier/trunk

    • Property svn:mergeinfo set to /quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier:1387-1389,1394-1413
  • quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/binary.py

    r453 r1414  
    2424        #self.excludekey = defaultMatcher(options, 'exclude-key', name, 'excluded_fields') 
    2525        self.excludekey = options.get('exclude-key', '_excluded_fields').strip() 
     26         
     27        self.doc = minidom.Document() 
    2628 
    2729    def __iter__(self): 
     
    7375        """ 
    7476        field = obj.getField(field) 
    75         base_unit = field.getBaseUnit(obj) 
     77        # temporarily: 
     78        # dirty call, I know, just lazy to get method arguments 
     79        # TextField overrided getBaseUnit method but didn't follow API 
     80        try: 
     81            base_unit = field.getBaseUnit(obj, full=True) 
     82        except TypeError, e: 
     83            base_unit = field.getBaseUnit(obj) 
    7684        fname = base_unit.getFilename()  
    7785        ct = base_unit.getContentType() 
     
    8189 
    8290    def createManifest(self, binary_fields): 
    83         manifest = '<?xml version="1.0" ?>\n<manifest>\n' 
    84         for field, info in binary_fields.items(): 
    85             manifest += '  <field name="%s">\n' % field 
    86             manifest += '    <filename>%s</filename>\n' % info['filename'] 
    87             manifest += '    <mimetype>%s</mimetype>\n' % info['mimetype'] 
    88             manifest += '  </field>\n' 
    89         manifest += "</manifest>\n" 
    90         return manifest 
     91        doc = self.doc 
     92 
     93        root = doc.createElement('manifest') 
     94        for fname, info in binary_fields.items(): 
     95            # create field node 
     96            field = doc.createElement('field') 
     97 
     98            # set name attribute 
     99            attr = doc.createAttribute('name') 
     100            attr.value = fname 
     101            field.setAttributeNode(attr) 
     102 
     103            # create filename node 
     104            filename = doc.createElement('filename') 
     105            filename.appendChild(doc.createTextNode(info['filename'])) 
     106            field.appendChild(filename) 
     107 
     108            # create mimetype node 
     109            mimetype = doc.createElement('mimetype') 
     110            mimetype.appendChild(doc.createTextNode(info['mimetype'])) 
     111            field.appendChild(mimetype) 
     112 
     113            root.appendChild(field) 
     114 
     115        doc.appendChild(root) 
     116 
     117        try: 
     118            data = doc.toprettyxml(indent='  ', encoding='utf-8') 
     119        except UnicodeDecodeError, e: 
     120            # all comments are strings encoded in 'utf-8' and they will properly 
     121            # saved in xml file, but if we explicitly give 'utf-8' encoding 
     122            # UnicodeDecodeError will be raised when they have non-ascii chars 
     123            data = doc.toprettyxml(indent='  ') 
     124 
     125        doc.unlink() 
     126        return data 
     127 
    91128 
    92129class FileImporterSection(object): 
  • quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/manifest.py

    r1240 r1414  
    2121        self.fileskey = options.get('files-key', '_files').strip() 
    2222 
     23        self.doc = minidom.Document() 
     24 
    2325    def __iter__(self): 
    2426        for item in self.previous: 
     
    4143        if not entries: 
    4244            return None 
    43         manifest = '<?xml version="1.0" ?>\n<manifest>\n' 
     45 
     46        doc = self.doc 
     47        root = doc.createElement('manifest') 
     48 
    4449        for obj_id, obj_type in entries: 
    45             manifest += '  <record type="%s">%s</record>\n' % (obj_type, obj_id) 
    46         manifest += "</manifest>\n" 
    47         return manifest 
     50            # create record 
     51            record = doc.createElement('record') 
     52 
     53            # set type attribute 
     54            attr = doc.createAttribute('type') 
     55            attr.value = obj_type 
     56            record.setAttributeNode(attr) 
     57 
     58            # add object id 
     59            text = doc.createTextNode(obj_id) 
     60            record.appendChild(text) 
     61 
     62            root.appendChild(record) 
     63 
     64        doc.appendChild(root) 
     65 
     66        try: 
     67            data = doc.toprettyxml(indent='  ', encoding='utf-8') 
     68        except UnicodeDecodeError, e: 
     69            # all comments are strings encoded in 'utf-8' and they will properly 
     70            # saved in xml file, but if we explicitly give 'utf-8' encoding 
     71            # UnicodeDecodeError will be raised when they have non-ascii chars 
     72            data = doc.toprettyxml(indent='  ') 
     73 
     74        doc.unlink() 
     75        return data 
    4876 
    4977class ManifestImporterSection(object): 
  • quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/marshall.py

    r527 r1414  
    1515from Products.Archetypes.event import ObjectInitializedEvent 
    1616from Products.Archetypes.event import ObjectEditedEvent 
     17 
     18# override Marshall atxml namespaces 
     19from quintagroup.transmogrifier import namespaces 
     20 
    1721 
    1822class MarshallerSection(object): 
Note: See TracChangeset for help on using the changeset viewer.