Beispiel #1
0
    def _parse_note_plist(plist):
        """Notes are stored in ASCII plist: extract the actual content."""
        try:
            tree = ElementTree.XML(plist)
        except ElementTree.ParseError:
            return None

        found = tree.find('.//string')
        if found is None:
            return None
        return found.text
Beispiel #2
0
 def from_format_to_fts_object(self, object: str, FTSObject: Event) -> Event:
     """ convert xmlstring to fts_object
     this function takes as input an xmlstring and it's corresponding FTSObject
     all data from the xmlstring is transfered to the FTS object and returned
     :param object:
     :param FTSObject:
     :return: an instance of the FTS model
     """
     element = etree.XML(object)
     self._xml_subelement_to_fts_nested(FTSObject, element, object)
     return self._xml_attribs_to_fts_properties(FTSObject, element)
Beispiel #3
0
 def __init__(self, root, modelObject):
     try:
         self.modelObject = modelObject
         root = root.encode()
         self.event = etree.XML(root)
         self.establishVariables()
         self.eventAtrib()
         self.pointAtrib()
         self.takvAtrib()
         self.contactAtrib()
         self.uidAtrib()
         self.precisionlocationAtrib()
         self.groupAtrib()
         self.statusAtrib()
         self.trackAtrib()
     except Exception as e:
         print(e)
Beispiel #4
0
    def _decode_data(self, entry):
        """Decode data field (password or comments)."""
        key = entry.get('type', 'password')
        key = 'comments' if key == 'note' else key
        data = entry.pop('data', '')
        if isinstance(data, int):
            return key, ''

        data = self._decode(data)
        if key == 'comments':
            if data:
                try:
                    tree = ElementTree.XML(data)
                except ElementTree.ParseError:
                    return key, ''

                found = tree.find('.//string')
                if found is None:
                    return key, ''
                return key, found.text
            return key, ''
        return key, data
Beispiel #5
0
    def parse(self):
        """Parse Clipperz HTML+JSON file."""
        # Extract the json from the html file.
        tree = ElementTree.XML(self.file.read())
        found = tree.find(self.html_header)
        if found is None:
            raise FormatError()

        # Parse JSON data
        keys = self.invkeys()
        for item in json.loads(found.text):
            entry = dict()
            label = item.get('label', ' \ue009').split(' \ue009')
            entry['title'] = label[0]
            if len(label) > 1:
                entry['group'] = label[1]

            fields = item.get('currentVersion', {}).get('fields', {})
            for uid in fields:
                label = fields[uid].get('label', '')
                entry[keys.get(label, label)] = fields[uid].get('value', '')

            entry['comments'] = item.get('data', {}).get('notes', '')
            self.data.append(entry)
Beispiel #6
0
 def parse(self, file):
     tree = ElementTree.XML(file.read())
     self._checkformat(tree)
     root = self._getroot(tree)
     self._import(root)