def decode_parties(self, pointer): """ ST.36: Decode list of applicants, inventors or agents. See also https://github.com/Patent2net/P2N/blob/develop/p2n/ops/decoder.py#L535 """ try: nodes = to_list(pointer.resolve(self._data)) except JsonPointerException: return [] entries = [] for party in nodes: addressbook = party['addressbook'] entry = OrderedDict() entry['name'] = addressbook['name']['$'] entry['text'] = addressbook['text']['$'] entry['country'] = addressbook['address']['country']['$'] address = [] for index in range(1, 7): fieldname = 'address-{}'.format(index) try: value = addressbook['address'][fieldname]['$'] address.append(value) except KeyError: pass entry['address'] = address entries.append(entry) return entries
def email_issue_report(report, recipients): recipients = to_list(recipients) identifier = None if isinstance(report, SmartBunch): identifier = report.meta.id # Build reasonable subject subject = 'Product issue' if 'dialog' in report and 'what' in report.dialog: subject = '[{}] '.format(report.dialog.what) + subject if identifier: subject += ' #' + identifier # Build reasonable message message = '' if 'dialog' in report and 'remark' in report.dialog: message = report.dialog.remark # Add JSON report as attachment files = {'report.json': report.pretty()} email = message_factory(recipients=recipients) email.send(subject=subject, message=message, files=files)
def convert_list(cls, things_raw, nested_element='$'): """Decode list of things""" things = [] for thing in to_list(things_raw): if not thing: continue if nested_element in thing and len(thing.keys()) == 1: thing = thing[nested_element] if isinstance(thing, dict): thing = cls.convert_dict(thing) things.append(thing) return things
def add_reply(self, address): for address in to_list(address): self.reply_to.append(address)
def add_recipient(self, address): for address in to_list(address): self.recipients.append(address)