示例#1
0
 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!")
示例#2
0
 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
示例#3
0
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'}
示例#4
0
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
示例#5
0
def load():
	for contact in defaultContacts:
		contactparser.add_contact(contact)
	return defaultWhois