# HG changeset patch # User Sylvain Thénault # Date 1475315787 -7200 # Node ID 9cb215e833b037d3b5beb5d259e291a3f83798df # Parent 6ab14a1afb6574a98c5267851bda2f37bf9b276f [cnx] Use entity_type instead of entity_metas()['type'] The latter is deprecated in favor of the former which has been introduced on cnx to replace it. diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/cwvreg.py --- a/cubicweb/cwvreg.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/cwvreg.py Sat Oct 01 11:56:27 2016 +0200 @@ -558,7 +558,7 @@ def solutions(self, req, rqlst, args): def type_from_eid(eid, req=req): - return req.entity_metas(eid)['type'] + return req.entity_type(eid) return self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args) def parse(self, req, rql, args=None): diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/hooks/integrity.py --- a/cubicweb/hooks/integrity.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/hooks/integrity.py Sat Oct 01 11:56:27 2016 +0200 @@ -87,7 +87,7 @@ if rtype in pendingrtypes: continue if not cnx.execute(self.base_rql % rtype, {'x': eid}): - etype = cnx.entity_metas(eid)['type'] + etype = cnx.entity_type(eid) msg = _('at least one relation %(rtype)s is required on ' '%(etype)s (%(eid)s)') raise validation_error(eid, {(rtype, self.role): msg}, diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/hooks/security.py --- a/cubicweb/hooks/security.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/hooks/security.py Sat Oct 01 11:56:27 2016 +0200 @@ -89,8 +89,8 @@ def precommit_event(self): cnx = self.cnx for action, rschema, eidfrom, eidto in self.get_data(): - rdef = rschema.rdef(cnx.entity_metas(eidfrom)['type'], - cnx.entity_metas(eidto)['type']) + rdef = rschema.rdef(cnx.entity_type(eidfrom), + cnx.entity_type(eidto)) rdef.check_perm(cnx, action, fromeid=eidfrom, toeid=eidto) @@ -165,8 +165,8 @@ if rschema.inlined and skip_inlined_relation_security( self._cw, rschema, self.eidfrom): return - rdef = rschema.rdef(self._cw.entity_metas(self.eidfrom)['type'], - self._cw.entity_metas(self.eidto)['type']) + rdef = rschema.rdef(self._cw.entity_type(self.eidfrom), + self._cw.entity_type(self.eidto)) rdef.check_perm(self._cw, 'add', fromeid=self.eidfrom, toeid=self.eidto) @@ -187,8 +187,8 @@ CheckRelationPermissionOp.get_instance(self._cw).add_data( ('add', rschema, self.eidfrom, self.eidto) ) else: - rdef = rschema.rdef(self._cw.entity_metas(self.eidfrom)['type'], - self._cw.entity_metas(self.eidto)['type']) + rdef = rschema.rdef(self._cw.entity_type(self.eidfrom), + self._cw.entity_type(self.eidto)) rdef.check_perm(self._cw, 'add', fromeid=self.eidfrom, toeid=self.eidto) @@ -204,6 +204,6 @@ if rschema.inlined and skip_inlined_relation_security( self._cw, rschema, self.eidfrom): return - rdef = rschema.rdef(self._cw.entity_metas(self.eidfrom)['type'], - self._cw.entity_metas(self.eidto)['type']) + rdef = rschema.rdef(self._cw.entity_type(self.eidfrom), + self._cw.entity_type(self.eidto)) rdef.check_perm(self._cw, 'delete', fromeid=self.eidfrom, toeid=self.eidto) diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/hooks/syncschema.py --- a/cubicweb/hooks/syncschema.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/hooks/syncschema.py Sat Oct 01 11:56:27 2016 +0200 @@ -1347,7 +1347,7 @@ def __call__(self): action = self.rtype.split('_', 1)[0] - if self._cw.entity_metas(self.eidto)['type'] == 'CWGroup': + if self._cw.entity_type(self.eidto) == 'CWGroup': MemSchemaPermissionAdd(self._cw, action=action, eid=self.eidfrom, group_eid=self.eidto) else: # RQLExpression @@ -1368,7 +1368,7 @@ if self._cw.deleted_in_transaction(self.eidfrom): return action = self.rtype.split('_', 1)[0] - if self._cw.entity_metas(self.eidto)['type'] == 'CWGroup': + if self._cw.entity_type(self.eidto) == 'CWGroup': MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom, group_eid=self.eidto) else: # RQLExpression diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/hooks/syncsession.py --- a/cubicweb/hooks/syncsession.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/hooks/syncsession.py Sat Oct 01 11:56:27 2016 +0200 @@ -257,7 +257,7 @@ def __call__(self): cnx = self._cw eidfrom = self.eidfrom - if not cnx.entity_metas(eidfrom)['type'] == 'CWProperty': + if not cnx.entity_type(eidfrom) == 'CWProperty': return key, value = cnx.execute('Any K,V WHERE P eid %(x)s,P pkey K,P value V', {'x': eidfrom})[0] diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/req.py --- a/cubicweb/req.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/req.py Sat Oct 01 11:56:27 2016 +0200 @@ -134,7 +134,7 @@ """ eid = int(eid) if etype is None: - etype = self.entity_metas(eid)['type'] + etype = self.entity_type(eid) rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid}, [(etype,)]) rset.req = self diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/schema.py --- a/cubicweb/schema.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/schema.py Sat Oct 01 11:56:27 2016 +0200 @@ -937,20 +937,20 @@ assert not ('fromeid' in kwargs or 'toeid' in kwargs), kwargs assert action in ('read', 'update') if 'eid' in kwargs: - subjtype = _cw.entity_metas(kwargs['eid'])['type'] + subjtype = _cw.entity_type(kwargs['eid']) else: subjtype = objtype = None else: assert 'eid' not in kwargs, kwargs assert action in ('read', 'add', 'delete') if 'fromeid' in kwargs: - subjtype = _cw.entity_metas(kwargs['fromeid'])['type'] + subjtype = _cw.entity_type(kwargs['fromeid']) elif 'frometype' in kwargs: subjtype = kwargs.pop('frometype') else: subjtype = None if 'toeid' in kwargs: - objtype = _cw.entity_metas(kwargs['toeid'])['type'] + objtype = _cw.entity_type(kwargs['toeid']) elif 'toetype' in kwargs: objtype = kwargs.pop('toetype') else: diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/server/hook.py --- a/cubicweb/server/hook.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/server/hook.py Sat Oct 01 11:56:27 2016 +0200 @@ -463,10 +463,10 @@ if kwargs.get('rtype') not in self.expected: return 0 if self.frometypes is not None and \ - req.entity_metas(kwargs['eidfrom'])['type'] not in self.frometypes: + req.entity_type(kwargs['eidfrom']) not in self.frometypes: return 0 if self.toetypes is not None and \ - req.entity_metas(kwargs['eidto'])['type'] not in self.toetypes: + req.entity_type(kwargs['eidto']) not in self.toetypes: return 0 return 1 @@ -607,7 +607,7 @@ def __call__(self): assert self.main_rtype for eid in (self.eidfrom, self.eidto): - etype = self._cw.entity_metas(eid)['type'] + etype = self._cw.entity_type(eid) if self.main_rtype not in self._cw.vreg.schema.eschema(etype).subjrels: return if self.rtype in self.subject_relations: @@ -643,7 +643,7 @@ skip_object_relations = () def __call__(self): - eschema = self._cw.vreg.schema.eschema(self._cw.entity_metas(self.eidfrom)['type']) + eschema = self._cw.vreg.schema.eschema(self._cw.entity_type(self.eidfrom)) execute = self._cw.execute for rel in self.subject_relations: if rel in eschema.subjrels and not rel in self.skip_subject_relations: @@ -667,7 +667,7 @@ events = ('after_delete_relation',) def __call__(self): - eschema = self._cw.vreg.schema.eschema(self._cw.entity_metas(self.eidfrom)['type']) + eschema = self._cw.vreg.schema.eschema(self._cw.entity_type(self.eidfrom)) execute = self._cw.execute for rel in self.subject_relations: if rel in eschema.subjrels and not rel in self.skip_subject_relations: diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/server/querier.py --- a/cubicweb/server/querier.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/server/querier.py Sat Oct 01 11:56:27 2016 +0200 @@ -68,7 +68,7 @@ try: return solution[term.name] except AttributeError: - return cnx.entity_metas(term.eval(args))['type'] + return cnx.entity_type(term.eval(args)) def check_relations_read_access(cnx, select, args): """Raise :exc:`Unauthorized` if the given user doesn't have credentials to @@ -682,7 +682,7 @@ def _build_descr(cnx, result, basedescription, todetermine): description = [] - entity_metas = cnx.entity_metas + entity_type = cnx.entity_type todel = [] for i, row in enumerate(result): row_descr = basedescription[:] @@ -696,7 +696,7 @@ row_descr[index] = etype_from_pyobj(value) else: try: - row_descr[index] = entity_metas(value)['type'] + row_descr[index] = entity_type(value) except UnknownEid: cnx.error('wrong eid %s in repository, you should ' 'db-check the database' % value) diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/server/session.py --- a/cubicweb/server/session.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/server/session.py Sat Oct 01 11:56:27 2016 +0200 @@ -606,7 +606,7 @@ rset.rows.append([targeteid]) if not isinstance(rset.description, list): # else description not set rset.description = list(rset.description) - rset.description.append([self.entity_metas(targeteid)['type']]) + rset.description.append([self.entity_type(targeteid)]) targetentity = self.entity_from_eid(targeteid) if targetentity.cw_rset is None: targetentity.cw_rset = rset diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/server/sources/native.py --- a/cubicweb/server/sources/native.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/server/sources/native.py Sat Oct 01 11:56:27 2016 +0200 @@ -644,7 +644,7 @@ else: # used by data import etypes = {} for subject, object in subj_obj_list: - etype = cnx.entity_metas(subject)['type'] + etype = cnx.entity_type(subject) if etype in etypes: etypes[etype].append((subject, object)) else: @@ -669,7 +669,7 @@ def _delete_relation(self, cnx, subject, rtype, object, inlined=False): """delete a relation from the source""" if inlined: - table = SQL_PREFIX + cnx.entity_metas(subject)['type'] + table = SQL_PREFIX + cnx.entity_type(subject) column = SQL_PREFIX + rtype sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column, SQL_PREFIX) diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/server/ssplanner.py --- a/cubicweb/server/ssplanner.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/server/ssplanner.py Sat Oct 01 11:56:27 2016 +0200 @@ -92,7 +92,7 @@ # to be selected) if checkread and eid not in neweids: with cnx.security_enabled(read=False): - eschema(cnx.entity_metas(eid)['type']).check_perm( + eschema(cnx.entity_type(eid)).check_perm( cnx, 'read', eid=eid) eidconsts[lhs.variable] = eid return eidconsts diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/sobjects/supervising.py --- a/cubicweb/sobjects/supervising.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/sobjects/supervising.py Sat Oct 01 11:56:27 2016 +0200 @@ -147,7 +147,7 @@ cnx = self._cw def describe(eid): try: - return cnx._(cnx.entity_metas(eid)['type']).lower() + return cnx._(cnx.entity_type(eid)).lower() except UnknownEid: # may occurs when an entity has been deleted from an external # source and we're cleaning its relation diff -r 6ab14a1afb65 -r 9cb215e833b0 cubicweb/web/request.py --- a/cubicweb/web/request.py Thu Oct 06 12:15:50 2016 +0200 +++ b/cubicweb/web/request.py Sat Oct 01 11:56:27 2016 +0200 @@ -1008,7 +1008,8 @@ self._ = self.__ = text_type self.pgettext = lambda x, y: text_type(y) - entity_metas = _cnx_func('entity_metas') + entity_metas = _cnx_func('entity_metas') # XXX deprecated + entity_type = _cnx_func('entity_type') source_defs = _cnx_func('source_defs') get_shared_data = _cnx_func('get_shared_data') set_shared_data = _cnx_func('set_shared_data')