Пример #1
0
    def processRequest(self, client_sock):
        dict_employees = json.loads(open(self.empLocation).read())['employees']
        em = Employee()
        employees = [em.from_dict(emp) for emp in dict_employees]

        caller = client_sock.recv(256)
        print('Received transport request from ', caller)
        # print('My neighbours are: ', self.neighbours)
        if caller == b'client':
            for neighbour in self.neighbours:
                print('Started a new transport client for ', neighbour)
                transClient = TransportClient()
                transClient.setLocation(neighbour.get_tuple())
                new_employees = transClient.getEmployees(b'maven')
                for employee in new_employees:
                    if employee not in employees:
                        employees.append(employee)
                # employees += new_employees

        pickled_data = pickle.dumps(employees)
        client_sock.send(pickled_data)
        client_sock.close()
Пример #2
0
import json, xmljson
from lxml.etree import tostring, fromstring, Element

from utils.utils import Employee


emp = Employee(name='name1', surname='surname1', salary='1', department='department1')
print(emp.to_xml_string())

# print(dict(Employee.from_xml(emp, emp.to_xml())['employee']))

print(Employee().from_xml_string(emp.to_xml_string()))

print(emp == Employee().from_xml_string(emp.to_xml_string()))

xml_string = emp.to_xml_string()

json_string = json.dumps(Employee().from_xml_string(xml_string).__dict__)

print(json_string)