def load_from_mongodb(cls, db, id, host=None, port=None): from pymongo import MongoClient try: import simplejson as json except ImportError: import json from jsonpickle import decode as json_decode if host == None: host = 'localhost' if port == None: port = 27017 client = MongoClient(host,port) db = client[db] collection = db[id] doc = collection.find_one() del doc['_id'] doc = json.dumps(doc) document = json_decode(doc) return document
def load_from_mongodb(cls, db, id, host=None, port=None): from pymongo import MongoClient import simplejson as json from jsonpickle import decode as json_decode if host == None: host = 'localhost' if port == None: port = 27017 client = MongoClient(host,port) db = client[db] collection = db[id] doc = collection.find_one() del doc['_id'] doc = json.dumps(doc) document = json_decode(doc) return document
def reconstruct_computer(serialized_computer): """ :param serialized_computer: string in json format :return: shared.hardware_objects_lib.Computer object """ computer = json_decode(serialized_computer) assert computer.__class__.__name__ == Computer.__name__ return computer
def load(cls,file): if isinstance(file,str): fileh = open(file,'r') else: fileh = file json_string = fileh.read() unpickled = json_decode(json_string) return unpickled
]), unpicklable=False)) file.flush() try: file_contents = read_connections_file() if not len(file_contents): write_empty_schema() except FileNotFoundError: write_empty_schema() file_contents = read_connections_file() servers = [ Server(uri=server['uri'], label=server['label']) for server in json_decode(file_contents)['servers'] ] connections = Connections(servers=servers) servers = '\n'.join( [f'{server.label} ({server.uri})' for server in connections.servers]) print(f'servers: \n{servers}') conn_to_uri = None while not conn_to_uri: conn_to = input('connect to: ') servers = [ server for server in connections.servers if server.label == conn_to ]
def decode_list_of_serialized_computers(list_of_computers_json: [str]): return [ json_decode(computer_json) for computer_json in list_of_computers_json ]