def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db['dimensions'] emf_logger.debug('dims table ={0}'.format(dims)) emf_logger.debug('group={0}'.format(group)) try: #this checks if there is any information about the group in question, sets rec to {'group': group} when it finds it if group == 0: rec = dims.find_one({'group': 'gamma0'}) self.dimension = self.dimension_gamma0 emf_logger.debug('rec={0}'.format(rec['_id'])) elif group == 1: rec = dims.find_one({'group': 'gamma1'}) self.dimension = self.dimension_gamma1 except: #if rec hasn't been set, then it didn't find the group rec = None emf_logger.critical( 'Critical error: No dimension information for group={0}'. format(group)) if rec != None: self._table = loads(rec['data']) if rec != None: self._table = loads( rec['data']) #loads the data for the group in _table else: self._table = None if self._table != None: emf_logger.debug('Have information for levels {0}'.format( self._table.keys()))
def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db['dimensions'] emf_logger.debug('dims table ={0}'.format(dims)) emf_logger.debug('group={0}'.format(group)) try: #this checks if there is any information about the group in question, sets rec to {'group': group} when it finds it if group == 0: rec = dims.find_one({'group': 'gamma0'}) self.dimension = self.dimension_gamma0 emf_logger.debug('rec={0}'.format(rec['_id'])) elif group == 1: rec = dims.find_one({'group': 'gamma1'}) self.dimension = self.dimension_gamma1 except: #if rec hasn't been set, then it didn't find the group rec = None emf_logger.critical('Critical error: No dimension information for group={0}'.format(group)) if rec!=None: self._table = loads(rec['data']) if rec != None: self._table = loads(rec['data']) #loads the data for the group in _table else: self._table = None if self._table != None: emf_logger.debug('Have information for levels {0}'.format(self._table.keys()))
def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db['dimensions'] emf_logger.debug('dims table ={0}'.format(dims)) emf_logger.debug('group={0}'.format(group)) try: if group == 0: rec = dims.find_one({'group': 'gamma0'}) self.dimension = self.dimension_gamma0 emf_logger.debug('rec={0}'.format(rec['_id'])) elif group == 1: rec = dims.find_one({'group': 'gamma1'}) self.dimension = self.dimension_gamma1 except: rec = None emf_logger.critical( 'Critical error: No dimension information for group={0}'. format(group)) if rec <> None: self._table = loads(rec['data']) else: self._table = None if self._table <> None: emf_logger.debug('Have information for levels {0}'.format( self._table.keys()))
def plot_maassform(maass_id): DB = connect_db() data = DB.get_maassform_plot_by_id(maass_id) data = data['plot'] response = make_response(loads(data)) response.headers['Content-type'] = 'image/png' return response
def _get_aps(self, prec=-1): r""" Get aps from database if they exist. """ ap_files = connect_to_modularforms_db('ap.files') key = {'k': int(self._k), 'N': int(self._N), 'cchi': int(self._chi)} key['prec'] = {"$gt": int(prec - 1)} ap_from_db = ap_files.find(key).sort("prec") wmf_logger.debug("finds={0}".format(ap_from_db)) wmf_logger.debug("finds.count()={0}".format(ap_from_db.count())) fs = get_files_from_gridfs('ap') aplist = {} for i in range(len(self.labels())): aplist[self.labels()[i]]={} for rec in ap_from_db: wmf_logger.debug("rec={0}".format(rec)) ni = rec.get('newform') if ni is None: for a in self.labels(): aplist[a][prec]=None return aplist a = self.labels()[ni] cur_prec = rec['prec'] if aplist.get(a,{}).get(cur_prec,None) is None: aplist[a][prec]=loads(fs.get(rec['_id']).read()) if cur_prec > prec and prec>0: # We are happy with these coefficients. return aplist return aplist
def pop(self): length = len(self) if not length: raise IndexError('cannot pop an empty stack') # Read and delete the position of the last chunk. with open(self._index, 'r+b') as f: f.seek(_INTSIZE * (length - 1)) pos, = struct.unpack(_INTSYMB, f.read(_INTSIZE)) f.seek(_INTSIZE * (length - 1)) f.truncate() # Read and delete the size of the last chunk. with open(self._sizes, 'r+b') as f: f.seek(_INTSIZE * (length - 1)) size, = struct.unpack(_INTSYMB, f.read(_INTSIZE)) f.seek(_INTSIZE * (length - 1)) f.truncate() # Read and delete the chunk itself. with open(self._data, 'r+b') as f: f.seek(pos) top = f.read(size) f.seek(pos) f.truncate() return loads(top)
def get_coefficients(self, data={}, verbose=0, **kwds): if verbose > 0: print("data=", data) maass_id = data.get('maass_id') if maass_id is None: raise ValueError if verbose > 0: print("id=", maass_id) f = db.mwf_forms.lucky({'maass_id': maass_id}) if f is None: return None #nc = f.get('Numc', 0) if verbose > 0: print("f=", f) #if nc == 0: # return None cid = f.get('coeff_label', None) if cid is None: R = f.get('Eigenvalue', None) if R is None: return f.get('Coefficients', None) R = [floor(R * 1E9) * 1E-9, ceil(R * 1E9) * 1E-9] for r in R: searchcoeffs = db.mwf_coeffs.search( {'label': { '$regex': str(r) }}) for res in searchcoeffs: c = res['coefficients'] if PY3: d = loads(bytes(c)) else: d = loads(str(c)) if type(d) == type([]): d = {i: d[i] for i in range(0, len(d))} e = self.find_coeffs_from_dict(d, type(d)) if (e is not None): return e return f.get('Coefficients', None) ff = db.mwf_coeffs.lucky({'label': cid}, 'coefficients') if ff is None: return None elif PY3: return loads(bytes(ff)) else: return loads(str(ff))
def load(self, key, compress=True): from pymongo.objectid import ObjectId if isinstance(key, ObjectId): data = self.gridfs.get(key).read() else: data = self.gridfs.get_last_version(key).read() from sage.all import loads return loads(data, compress=compress)
def get_file(self, add_to_fs_query=None, get_all=False, meta_only=False, ignore_multi_if_failed=True): r""" Get the file(s) from gridfs. """ if not self._use_gridfs: raise ValueError('We do not use gridfs for this class.') fs = self._files emf_logger.debug("{} self._add_to_fs_query: {}".format( self.__class__, self._add_to_fs_query)) if add_to_fs_query is None: add_to_fs_query = self._add_to_fs_query elif self._add_to_fs_query is not None: q = add_to_fs_query add_to_fs_query = copy(self._add_to_fs_query) add_to_fs_query.update(q) file_key = self.file_key_dict(include_multi=not get_all) if add_to_fs_query is not None and not get_all: file_key.update(add_to_fs_query) sort = self._sort_files emf_logger.debug("{} add_to_fs_query: {}".format( self.__class__, add_to_fs_query)) emf_logger.debug("file_key: {0} fs={1}".format(file_key, self._file_collection)) results = [] if fs.exists(file_key): coll = self._file_collection if get_all: files = coll.find(file_key, sort=sort) else: files = [coll.find_one(file_key, sort=sort)] for m in files: fid = m['_id'] #emf_logger.debug("col={0}".format(coll)) #emf_logger.debug("rec={0}".format(coll.find_one(file_key))) if not meta_only: try: d = loads(fs.get(fid).read()) results.append((d, m)) except ValueError as e: raise ValueError( "Wrong format in database! : {0} coll: {1} rec:{2}" .format(e, coll, r)) else: results.append(m) else: raise IndexError( "File not found with file_key = {}".format(file_key)) emf_logger.debug("len(results) = {}".format(len(results))) if len(results) == 1 and not get_all: return results[0] else: return results
def plot_maassform(maass_id): r""" Render the plot of the Maass waveform as a pg-file. Loads it from the database. """ plot = maass_db.get_maassform_plot_by_id(maass_id) if not plot: return flask.abort(404) response = make_response(loads(plot)) response.headers['Content-type'] = 'image/png' return response
def plot_maassform(maass_id): r""" Render the plot of the Maass waveform as a pg-file. Loads it from the database. """ DB = connect_db() data = DB.get_maassform_plot_by_id(maass_id) data = data['plot'] response = make_response(loads(data)) response.headers['Content-type'] = 'image/png' return response
def plot_maassform(maass_id): r""" Render the plot of the Maass waveform as a pg-file. Loads it from the database. """ plot = maass_db.get_maassform_plot_by_id(maass_id) if not plot: return flask.abort(404) response = make_response(loads(Binary(str(plot), 0))) response.headers['Content-type'] = 'image/png' return response
def pickle(base64): r""" A base64 encoded pickle. """ from base64 import b64decode from sage.all import loads encoded = b64decode(base64.strip().encode("ASCII")) return { "bindings": [FactoryBindingSpec("surface", lambda: loads(encoded))] }
def verify_result(i,result_dir="kamienny_run",verbose=True): if i['result_type']=='single' and i['satisfied']: torsion,congruence=i['torsion_order'],i['congruence_type'] C = KamiennyCriterion(i['torsion_order'],i['congruence_type']) v=None if i['use_rand_vec']: result_filename=os.path.join(result_dir,"result_%s_%s"%(torsion,congruence)) with open(result_filename) as file: v=loads(file.read()) satisfied,message,dependencies = C.verify_criterion(i['degree'],n=i['n'], q=i['q'],p=i['p'],v=v,use_rand_vec=i['use_rand_vec']) if verbose and not satisfied: print("The following result is corrupt: %s"%(i)) return satisfied return True
def verify_result(i,result_dir="kamienny_run",verbose=True): if i['result_type']=='single' and i['satisfied']: torsion,congruence=i['torsion_order'],i['congruence_type'] C = KamiennyCriterion(i['torsion_order'],i['congruence_type']) v=None if i['use_rand_vec']: result_filename=os.path.join(result_dir,"result_%s_%s"%(torsion,congruence)) with open(result_filename) as file: v=loads(file.read()) satisfied,message,dependencies = C.verify_criterion(i['degree'],n=i['n'], q=i['q'],p=i['p'],v=v,use_rand_vec=i['use_rand_vec']) if verbose and not satisfied: print "The following result is corrupt: %s"%(i) return satisfied return True
def as_factor(self): r""" Return self as a newform factor """ if self._as_factor is None: C = connect_to_modularforms_db('Newform_factors.files') s = {'N':int(self.level()),'k':int(self.weight()), 'cchi':int(self.chi()),'newform':int(self.newform_number())} res = C.find_one(s) print res if not res is None: fid = res['_id'] fs = get_files_from_gridfs('Newform_factors') self._as_factor = loads(fs.get(fid).read()) if self._as_factor is None: raise ValueError,"Newform matching {0} can not be found".format(s) return self._as_factor
def get_file(self, add_to_fs_query=None, get_all=False, meta_only=False, ignore_multi_if_failed=True): r""" Get the file(s) from gridfs. """ if not self._use_gridfs: raise ValueError('We do not use gridfs for this class.') fs = self._files emf_logger.debug("{} self._add_to_fs_query: {}".format(self.__class__, self._add_to_fs_query)) if add_to_fs_query is None: add_to_fs_query = self._add_to_fs_query elif self._add_to_fs_query is not None: q=add_to_fs_query add_to_fs_query = copy(self._add_to_fs_query) add_to_fs_query.update(q) file_key = self.file_key_dict(include_multi = not get_all) if add_to_fs_query is not None and not get_all: file_key.update(add_to_fs_query) sort = self._sort_files emf_logger.debug("{} add_to_fs_query: {}".format(self.__class__, add_to_fs_query)) emf_logger.debug("file_key: {0} fs={1}".format(file_key,self._file_collection)) results = [] if fs.exists(file_key): coll = self._file_collection if get_all: files = coll.find(file_key, sort = sort) else: files = [coll.find_one(file_key, sort = sort)] for m in files: fid = m['_id'] #emf_logger.debug("col={0}".format(coll)) #emf_logger.debug("rec={0}".format(coll.find_one(file_key))) if not meta_only: try: d = loads(fs.get(fid).read()) results.append((d,m)) except ValueError as e: raise ValueError("Wrong format in database! : {0} coll: {1} rec:{2}".format(e,coll,m)) else: results.append(m) else: raise IndexError("File not found with file_key = {}".format(file_key)) emf_logger.debug("len(results) = {}".format(len(results))) if len(results) == 1 and not get_all: return results[0] else: return results
def get_from_db(self): r""" Fetch dictionary data from the database. """ db = connect_to_modularforms_db('WebModformspace.files') s = {'name':self._name,'version':emf_version} wmf_logger.debug("Looking in DB for rec={0}".format(s)) f = db.find_one(s) wmf_logger.debug("Found rec={0}".format(f)) if f<>None: id = f.get('_id') fs = get_files_from_gridfs('WebModformspace') f = fs.get(id) wmf_logger.debug("Getting rec={0}".format(f)) d = loads(f.read()) return d return {}
def plot_maassform(maass_id): r""" Render the plot of the Maass waveform as a pg-file. Loads it from the database. """ try: maass_id = bson.objectid.ObjectId(maass_id) except bson.errors.InvalidId: return flask.abort(404) DB = connect_db() data = DB.get_maassform_plot_by_id(maass_id) if not data: return flask.abort(404) data = data['plot'] response = make_response(loads(data)) response.headers['Content-type'] = 'image/png' return response
def get_modular_symbols(self): r""" Get Modular Symbols from database they exist. """ if not self._modular_symbols is None: return modular_symbols = connect_to_modularforms_db('Modular_symbols.files') key = {'k': int(self._k), 'N': int(self._N), 'cchi': int(self._chi)} modular_symbols_from_db = modular_symbols.find_one(key) wmf_logger.debug("found ms={0}".format(modular_symbols_from_db)) if modular_symbols_from_db is None: ms = None else: id = modular_symbols_from_db['_id'] fs = get_files_from_gridfs('Modular_symbols') ms = loads(fs.get(id).read()) self._id = id self._modular_symbols = ms
def __init__(self, filename, compresslevel=9): self._filename = filename self._meta_filename = filename + '.meta' self._compresslevel = compresslevel try: f = open(self._meta_filename, 'rb') except IOError: # No metadata -> start from scratch. self._critical = set() self._cand = dict() self._count = 0 self._file = gzip.open(filename, 'wb', compresslevel) else: # Recover metadata and open file for appending. with f: D = loads(f.read()) self._cand, self._critical, self._count = D['cand'], D['critical'], D['count'] self._file = gzip.open(filename, 'ab', compresslevel)
def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db['dimensions'] emf_logger.debug('group={0}'.format(group)) try: if group == 0: rec = dims.find_one({'group': 'gamma0'}) self.dimension = self.dimension_gamma0 # emf_logger.debug('rec={0}'.format(rec)) elif group == 1: rec = dims.find_one({'group': 'gamma1'}) self.dimension = self.dimension_gamma1 except: emf_logger.critical('Critical error: No dimension information for group={0}'.format(group)) if rec: self._table = loads(rec['data']) else: self._table = None
def __getitem__(self, index): if index < 0: index = len(self) - index if index < 0 or index >= len(self): raise IndexError('index out of range') # Get position with open(self._index, 'rb') as f: f.seek(_INTSIZE * index) pos, = struct.unpack(_INTSYMB, f.read(_INTSIZE)) # Get size with open(self._sizes, 'rb') as f: f.seek(_INTSIZE * index) size, = struct.unpack(_INTSYMB, f.read(_INTSIZE)) # Read data with open(self._data, 'rb') as f: f.seek(pos) return loads(f.read(size))
def get_coefficients(self, data={}, verbose=0, **kwds): if verbose > 0: print "data=", data maass_id = data.get('maass_id') if maass_id is None: raise ValueError if verbose > 0: print "id=", maass_id f = db.mwf_forms.lucky({'maass_id': maass_id}) if f is None: return None nc = f.get('Numc', 0) if verbose > 0: print "f=", f if nc == 0: return None cid = f.get('coeff_label', None) if cid is None: return f.get('Coefficients', None) ff = db.mwf_coeffs.lucky({'label': cid}, 'coefficients') return None if ff is None else loads(str(ff))
def get_coefficients(self, data={}, verbose=0, **kwds): if verbose > 0: print "data=", data maass_id = data.get('maass_id') if maass_id is None: raise ValueError if verbose > 0: print "id=", maass_id f = db.mwf_forms.lucky({'maass_id': maass_id}) if f is None: return None nc = f.get('Numc', 0) if verbose > 0: print "f=", f if nc == 0: return None cid = f.get('coeff_label', None) if cid is None: return f.get('Coefficients', None) ff = db.mwf_coeffs.lucky({'label':cid}, 'coefficients') return None if ff is None else loads(str(ff))
def get_newform_factors(self): r""" Get New form factors from database they exist. """ if not self._newforms is None and self._newforms == []: return factors = connect_to_modularforms_db('Newform_factors.files') key = {'k': int(self._k), 'N': int(self._N), 'cchi': int(self._chi),} factors_from_db = factors.find(key).sort('newform',int(1)) wmf_logger.debug("found factors={0}".format(factors_from_db)) self._newforms = {} if factors_from_db.count()==0: raise ValueError,"Space is not in database!" else: facts = [] self._labels = [] fs = get_files_from_gridfs('Newform_factors') for rec in factors_from_db: factor = loads(fs.get(rec['_id']).read()) label = orbit_label(rec['newform']) self._galois_orbits_labels.append(label) self._newforms[label] = factor
def get_atkin_lehner_eigenvalues(self): r""" Get the Atkin-Lehner eigenvalues from database if they exist. """ if not ((self.character().is_trivial() or self.character().order() == 2) and not self._atkin_lehner_eigenvalues is None): return None C = connect_to_modularforms_db('Atkin-Lehner.files') fs = get_files_from_gridfs('Atkin-Lehner') s = {'N':int(self.level()),'k':int(self.weight()), 'cchi':int(self.chi()),'newform':int(self.newform_number())} res = C.find_one(s) self._atkin_lehner_eigenvalues = {} if not res is None: alid = res['_id'] al = loads(fs.get(alid).read()) for d in prime_divisors(self.level()): self._atkin_lehner_eigenvalues[d] = 1 if al[d]=='+' else -1 else: # We compute them A = self.as_factor() for p in prime_divisors(self.level()): self._atkin_lehner_eigenvalues[p]= int(A.atkin_lehner_operator(p).matrix()[0,0])
def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db["dimensions"] emf_logger.debug("dims table ={0}".format(dims)) emf_logger.debug("group={0}".format(group)) try: if group == 0: rec = dims.find_one({"group": "gamma0"}) self.dimension = self.dimension_gamma0 emf_logger.debug("rec={0}".format(rec["_id"])) elif group == 1: rec = dims.find_one({"group": "gamma1"}) self.dimension = self.dimension_gamma1 except: rec = None emf_logger.critical("Critical error: No dimension information for group={0}".format(group)) if rec <> None: self._table = loads(rec["data"]) else: self._table = None emf_logger.debug("Have information for levels {0}".format(self._table.keys()))
def __init__(self, group=0): self._group = group self._table = dict() db = connect_db() dims = db['dimensions'] emf_logger.debug('dims table ={0}'.format(dims)) emf_logger.debug('group={0}'.format(group)) try: if group == 0: rec = dims.find_one({'group': 'gamma0'}) self.dimension = self.dimension_gamma0 emf_logger.debug('rec={0}'.format(rec['_id'])) elif group == 1: rec = dims.find_one({'group': 'gamma1'}) self.dimension = self.dimension_gamma1 except: rec = None emf_logger.critical('Critical error: No dimension information for group={0}'.format(group)) if rec<>None: self._table = loads(rec['data']) else: self._table = None if self._table <> None: emf_logger.debug('Have information for levels {0}'.format(self._table.keys()))
def from_fs(self, f): return loads(f)
def update_from_db(self, ignore_non_existent = True, \ add_to_fs_query=None, add_to_db_query=None): r""" Updates the properties of ```self``` from the database using params and dbkey. """ self._has_updated_from_db = False self._has_updated_from_fs = False if add_to_db_query is None: add_to_db_query = self._add_to_db_query elif self._add_to_db_query is not None: q = add_to_db_query add_to_db_query = copy(self._add_to_db_query) add_to_db_query.update(q) if add_to_fs_query is None: add_to_fs_query = self._add_to_fs_query elif self._add_to_fs_query is not None: q = add_to_fs_query add_to_fs_query = copy(self._add_to_fs_query) add_to_fs_query.update(q) #emf_logger.debug("add_to_fs_query: {0}".format(add_to_fs_query)) #emf_logger.debug("self._add_to_fs_query: {0}".format(self._add_to_fs_query)) emf_logger.debug("db_properties: {0}".format(self._db_properties)) succ_db = False succ_fs = False if self._use_separate_db or not self._use_gridfs: coll = self._collection key = self.key_dict() if add_to_db_query is not None: key.update(add_to_db_query) emf_logger.debug("key: {0} for {1}".format(key, self._collection_name)) if coll.find(key).count() > 0: props_to_fetch = {} #p.name:True for p in self._key} for p in self._db_properties: if p.include_in_update and ( not p.name in self._fs_properties or p._extend_fs_with_db): props_to_fetch[p.name] = True p.has_been_set(False) # props_to_fetch = {p.name:True for p in self._db_properties # if (p.include_in_update and not p.name in self._fs_properties) # or p.name in self._key} emf_logger.debug("props_to_fetch: {0}".format(props_to_fetch)) rec = coll.find_one(key, projection=props_to_fetch) for pn in props_to_fetch: p = self._properties[pn] if rec.has_key(pn): try: p.set_from_db(rec[pn]) if not p.name in self._fs_properties: p.has_been_set(True) except NotImplementedError: continue succ_db = True else: emf_logger.critical( "record with key:{0} was not found!".format(key)) if not ignore_non_existent: raise IndexError("DB record does not exist") succ_db = False if self._use_gridfs: fs = self._files file_key = self.file_key_dict() if add_to_fs_query is not None: file_key.update(add_to_fs_query) emf_logger.debug("add_to_fs_query: {0}".format(add_to_fs_query)) emf_logger.debug("file_key: {0} fs={1}".format( file_key, self._file_collection)) if fs.exists(file_key): coll = self._file_collection r = coll.find_one(file_key) fid = r['_id'] #emf_logger.debug("col={0}".format(coll)) #emf_logger.debug("rec={0}".format(coll.find_one(file_key))) try: d = loads(fs.get(fid).read()) except ValueError as e: raise ValueError( "Wrong format in database! : {0} coll: {1} rec:{2}". format(e, coll, r)) #emf_logger.debug("type(d)={0}".format(type(d))) #emf_logger.debug("d.keys()={0}".format(d.keys())) for p in self._fs_properties: #emf_logger.debug("p={0}, update:{1}".format(p,p.include_in_update)) #emf_logger.debug("d[{0}]={1}".format(p.name,type(d.get(p.name)))) if p.include_in_update and d.has_key(p.name): emf_logger.debug("d[{0}]={1}".format( p.name, type(d.get(p.name)))) p.has_been_set(False) p.set_from_fs(d[p.name]) succ_fs = True else: if not ignore_non_existent: raise IndexError("File does not exist") succ_fs = False emf_logger.debug("loaded from fs") if succ_db: self._has_updated_from_db = True if succ_fs: self._has_updated_from_fs = True
def update_from_db(self, ignore_non_existent = True, \ add_to_fs_query=None, add_to_db_query=None): r""" Updates the properties of ```self``` from the database using params and dbkey. """ self._has_updated_from_db = False self._has_updated_from_fs = False if add_to_db_query is None: add_to_db_query = self._add_to_db_query elif self._add_to_db_query is not None: q=add_to_db_query add_to_db_query = copy(self._add_to_db_query) add_to_db_query.update(q) if add_to_fs_query is None: add_to_fs_query = self._add_to_fs_query elif self._add_to_fs_query is not None: q=add_to_fs_query add_to_fs_query = copy(self._add_to_fs_query) add_to_fs_query.update(q) #emf_logger.debug("add_to_fs_query: {0}".format(add_to_fs_query)) #emf_logger.debug("self._add_to_fs_query: {0}".format(self._add_to_fs_query)) emf_logger.debug("db_properties: {0}".format(self._db_properties)) succ_db = False succ_fs = False if self._use_separate_db or not self._use_gridfs: coll = self._collection key = self.key_dict() if add_to_db_query is not None: key.update(add_to_db_query) emf_logger.debug("key: {0} for {1}".format(key,self._collection_name)) if coll.find(key).count()>0: props_to_fetch = { } #p.name:True for p in self._key} for p in self._db_properties: if p.include_in_update and (not p.name in self._fs_properties or p._extend_fs_with_db): props_to_fetch[p.name] = True p.has_been_set(False) # props_to_fetch = {p.name:True for p in self._db_properties # if (p.include_in_update and not p.name in self._fs_properties) # or p.name in self._key} emf_logger.debug("props_to_fetch: {0}".format(props_to_fetch)) rec = coll.find_one(key, projection = props_to_fetch) for pn in props_to_fetch: p = self._properties[pn] if rec.has_key(pn): try: p.set_from_db(rec[pn]) if not p.name in self._fs_properties: p.has_been_set(True) except NotImplementedError: continue succ_db = True else: emf_logger.critical("record with key:{0} was not found!".format(key)) if not ignore_non_existent: raise IndexError("DB record does not exist") succ_db = False if self._use_gridfs: fs = self._files file_key = self.file_key_dict() if add_to_fs_query is not None: file_key.update(add_to_fs_query) emf_logger.debug("add_to_fs_query: {0}".format(add_to_fs_query)) emf_logger.debug("file_key: {0}".format(file_key)) if fs.exists(file_key): coll = self._file_collection fid = coll.find_one(file_key)['_id'] #emf_logger.debug("col={0}".format(coll)) #emf_logger.debug("rec={0}".format(coll.find_one(file_key))) try: d = loads(fs.get(fid).read()) except ValueError as e: raise ValueError("Wrong format in database! : {0}".format(e)) #emf_logger.debug("type(d)={0}".format(type(d))) #emf_logger.debug("d.keys()={0}".format(d.keys())) for p in self._fs_properties: #emf_logger.debug("p={0}, update:{1}".format(p,p.include_in_update)) #emf_logger.debug("d[{0}]={1}".format(p.name,type(d.get(p.name)))) if p.include_in_update and d.has_key(p.name): p.has_been_set(False) p.set_from_fs(d[p.name]) succ_fs = True else: if not ignore_non_existent: raise IndexError("File does not exist") succ_fs = False if succ_db: self._has_updated_from_db = True if succ_fs: self._has_updated_from_fs = True
def _test(self): from sage.all import QuadraticField, loads, dumps K = QuadraticField(-1, 'i') if loads(dumps(K.maximal_order())) is not K.maximal_order(): raise Exception("#24934 has not been fixed")