def update_whois_info(id, wInfo): for entry in EntryContainer.entries: if entry.id == id: for contact in wInfo.contacts: if contactparser.contact_exists(contact.id): res, status = contactparser.edit_contact( contact.id, contact) if status != 200: raise Fault( faultcode="Server", faultstring= "Internal error when updating contacts!") else: res, status = contactparser.add_contact(contact) if status != 201: raise Fault(faultcode="Server", faultstring= "Internal error when adding contacts!") entry.id = wInfo.id entry.website = wInfo.website entry.ipaddress = wInfo.ipaddress entry.contacts = wInfo.contacts return wInfo raise Fault(faultcode="Client", faultstring="Could not find entry with given id!")
def add_whois_info(wInfo): for entry in EntryContainer.entries: if entry.id == wInfo.id: raise Fault(faultcode="Client", faultstring="Item with given ID already exists") for contact in wInfo.contacts: if contactparser.contact_exists(contact.id): res, status = contactparser.edit_contact(contact.id, contact) if status != 200: raise Fault( faultcode="Server", faultstring="Internal error when updating contacts!") else: res, status = contactparser.add_contact(contact) if status != 201: raise Fault( faultcode="Server", faultstring="Internal error when adding contacts!") EntryContainer.entries.append(wInfo) return wInfo
def add_info(): jsn = request.get_json() if jsn == None: return 'Bad request, either non json or needs \'application/json\' set as Content-Type in headers', 400 wInfo = WhoisInfo.deserialize(jsn) for entry in EntryContainer.entries: if entry.id == wInfo.id: return 'Item with such ID already exists!', 400 for contact in wInfo.contacts: if contactparser.contact_exists(contact.id): res, status = contactparser.edit_contact(contact.id, contact) if status != 200: return 'Internal error when updating contacts! ' + res, 500 else: res, status = contactparser.add_contact(contact) if status != 201: return 'Internal error when adding contacts! ' + res, 500 EntryContainer.entries.append(wInfo) json_string = json.dumps(wInfo.serialize()) return json_string, 201, {'Content-Type': 'application/json'}
def update_info(id): jsn = request.get_json() if jsn == None: return 'Bad request, either non json or needs \'application/json\' set as Content-Type in headers', 400 wInfo = WhoisInfo.deserialize(jsn) for entry in EntryContainer.entries: if entry.id == id: for contact in wInfo.contacts: if contactparser.contact_exists(contact.id): res, status = contactparser.edit_contact(contact.id, contact) if status != 200: return 'Internal error when updating contacts! ' + res, 500 else: res, status = contactparser.add_contact(contact) if status != 201: return 'Internal error when adding contacts! ' + res, 500 entry.id = wInfo.id entry.website = wInfo.website entry.ipaddress = wInfo.ipaddress entry.contacts = wInfo.contacts json_string = json.dumps(entry.serialize()) return json_string, 201, {'Content-Type': 'application/json'} return 'Could not find such item!', 404
def load(): for contact in defaultContacts: contactparser.add_contact(contact) return defaultWhois