Commit 79a8accc authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

drop typed_eid() in favour of int() (closes #2742462)

typed_eid was introduced to abstract the eid type when running on Google AppEngine.
It is not used anymore and can be removed. Let's use int() instead.
parent c0d4244e5abc
......@@ -38,10 +38,10 @@ CW_SOFTWARE_ROOT = __path__[0]
import sys, os, logging
from StringIO import StringIO
from logilab.common.deprecation import deprecated
from logilab.common.logging_ext import set_log_methods
from yams.constraints import BASE_CONVERTERS
if os.environ.get('APYCOT_ROOT'):
logging.basicConfig(level=logging.CRITICAL)
else:
......@@ -57,8 +57,9 @@ from cubicweb._exceptions import *
from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound
# convert eid to the right type, raise ValueError if it's not a valid eid
typed_eid = int
@deprecated('[3.17] typed_eid() was removed. replace it with int() when needed.')
def typed_eid(eid):
return int(eid)
#def log_thread(f, w, a):
# print f.f_code.co_filename, f.f_code.co_name
......
......@@ -24,7 +24,7 @@ from warnings import warn
from logilab.common.deprecation import deprecated
from logilab.common.decorators import cached
from cubicweb import Unauthorized, typed_eid
from cubicweb import Unauthorized
from cubicweb.entity import Entity
......
......@@ -33,7 +33,7 @@ from rql.stmts import Select
from rql.nodes import (Not, VariableRef, Constant, make_relation,
Relation as RqlRelation)
from cubicweb import Unauthorized, typed_eid, neg_role
from cubicweb import Unauthorized, neg_role
from cubicweb.utils import support_args
from cubicweb.rset import ResultSet
from cubicweb.appobject import AppObject
......@@ -627,7 +627,7 @@ class Entity(AppObject):
meaning that the entity has to be created
"""
try:
typed_eid(self.eid)
int(self.eid)
return True
except (ValueError, TypeError):
return False
......
......@@ -29,7 +29,7 @@ from logilab.common.decorators import cached
from logilab.common.deprecation import deprecated
from logilab.common.date import ustrftime, strptime, todate, todatetime
from cubicweb import Unauthorized, NoSelectableObject, typed_eid, uilib
from cubicweb import Unauthorized, NoSelectableObject, uilib
from cubicweb.rset import ResultSet
ONESECOND = timedelta(0, 1, 0)
......@@ -114,7 +114,7 @@ class RequestSessionBase(object):
(we have the eid, we can suppose it exists and user has access to the
entity)
"""
eid = typed_eid(eid)
eid = int(eid)
if etype is None:
etype = self.describe(eid)[0]
rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid},
......
......@@ -30,7 +30,7 @@ from yams import BadSchemaDefinition
from logilab.common import tempattr
from logilab.common.graph import has_path
from cubicweb import Unauthorized, typed_eid
from cubicweb import Unauthorized
def add_types_restriction(schema, rqlst, newroot=None, solutions=None):
......@@ -220,7 +220,7 @@ class RQLRewriter(object):
vi = {}
self.varinfos.append(vi)
try:
vi['const'] = typed_eid(selectvar)
vi['const'] = int(selectvar)
vi['rhs_rels'] = vi['lhs_rels'] = {}
except ValueError:
try:
......
......@@ -31,7 +31,7 @@ from rql.nodes import (Relation, VariableRef, Constant, SubQuery, Function,
from yams import BASE_TYPES
from cubicweb import ValidationError, Unauthorized, QueryError, UnknownEid
from cubicweb import Binary, server, typed_eid
from cubicweb import Binary, server
from cubicweb.rset import ResultSet
from cubicweb.utils import QueryCache, RepeatList
......@@ -391,7 +391,7 @@ class ExecutionPlan(object):
for var in rqlst.defined_vars.itervalues():
if var.stinfo['constnode'] is not None:
eid = var.stinfo['constnode'].eval(self.args)
varkwargs[var.name] = typed_eid(eid)
varkwargs[var.name] = int(eid)
# dictionary of variables restricted for security reason
localchecks = {}
restricted_vars = set()
......@@ -563,11 +563,11 @@ class InsertPlan(ExecutionPlan):
for subj, rtype, obj in self.relation_defs():
# if a string is given into args instead of an int, we get it here
if isinstance(subj, basestring):
subj = typed_eid(subj)
subj = int(subj)
elif not isinstance(subj, (int, long)):
subj = subj.entity.eid
if isinstance(obj, basestring):
obj = typed_eid(obj)
obj = int(obj)
elif not isinstance(obj, (int, long)):
obj = obj.entity.eid
if repo.schema.rschema(rtype).inlined:
......
......@@ -50,7 +50,7 @@ from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, QueryError,
UnknownEid, AuthenticationError, ExecutionError,
ETypeNotSupportedBySources, MultiSourcesError,
BadConnectionId, Unauthorized, ValidationError,
RepositoryError, UniqueTogetherError, typed_eid, onevent)
RepositoryError, UniqueTogetherError, onevent)
from cubicweb import cwvreg, schema, server
from cubicweb.server import ShuttingDown, utils, hook, pool, querier, sources
from cubicweb.server.session import Session, InternalSession, InternalManager
......@@ -1018,7 +1018,7 @@ class Repository(object):
uri)` for the entity of the given `eid`
"""
try:
eid = typed_eid(eid)
eid = int(eid)
except ValueError:
raise UnknownEid(eid)
try:
......@@ -1046,7 +1046,7 @@ class Repository(object):
rqlcache = self.querier._rql_cache
for eid in eids:
try:
etype, uri, extid, auri = etcache.pop(typed_eid(eid)) # may be a string in some cases
etype, uri, extid, auri = etcache.pop(int(eid)) # may be a string in some cases
rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None)
extidcache.pop((extid, uri), None)
except KeyError:
......@@ -1075,7 +1075,7 @@ class Repository(object):
key, args[key]))
cachekey.append(etype)
# ensure eid is correctly typed in args
args[key] = typed_eid(args[key])
args[key] = int(args[key])
return tuple(cachekey)
def eid2extid(self, source, eid, session=None):
......
......@@ -26,7 +26,7 @@ from logilab.common.shellutils import ProgressBar
from yams import BadSchemaDefinition, schema as schemamod, buildobjs as ybo
from cubicweb import CW_SOFTWARE_ROOT, typed_eid
from cubicweb import CW_SOFTWARE_ROOT
from cubicweb.schema import (CONSTRAINTS, ETYPE_NAME_MAP,
VIRTUAL_RTYPES, PURE_VIRTUAL_RTYPES)
from cubicweb.server import sqlutils
......@@ -58,7 +58,7 @@ def group_mapping(cursor, interactive=True):
if not value:
continue
try:
eid = typed_eid(value)
eid = int(value)
except ValueError:
print 'eid should be an integer'
continue
......
......@@ -22,7 +22,7 @@ __docformat__ = "restructuredtext en"
from rql.stmts import Union, Select
from rql.nodes import Constant, Relation
from cubicweb import QueryError, typed_eid
from cubicweb import QueryError
from cubicweb.schema import VIRTUAL_RTYPES
from cubicweb.rqlrewrite import add_types_restriction
from cubicweb.server.edition import EditedEntity
......@@ -79,7 +79,7 @@ def _extract_eid_consts(plan, rqlst):
if rel.r_type == 'eid' and not rel.neged(strict=True):
lhs, rhs = rel.get_variable_parts()
if isinstance(rhs, Constant):
eid = typed_eid(rhs.eval(plan.args))
eid = int(rhs.eval(plan.args))
# check read permission here since it may not be done by
# the generated select substep if not emited (eg nothing
# to be selected)
......@@ -516,7 +516,7 @@ class DeleteEntitiesStep(Step):
"""execute this step"""
results = self.execute_child()
if results:
todelete = frozenset(typed_eid(eid) for eid, in results)
todelete = frozenset(int(eid) for eid, in results)
session = self.plan.session
session.repo.glob_delete_entities(session, todelete)
return results
......@@ -562,7 +562,7 @@ class UpdateStep(Step):
lhsval = _handle_relterm(lhsinfo, row, newrow)
rhsval = _handle_relterm(rhsinfo, row, newrow)
if rschema.final or rschema.inlined:
eid = typed_eid(lhsval)
eid = int(lhsval)
try:
edited = edefs[eid]
except KeyError:
......
......@@ -42,7 +42,7 @@ from logilab.common.decorators import classproperty
from yams.constraints import BASE_CONVERTERS
from yams.schema import role_name as rn
from cubicweb import ValidationError, RegistryException, typed_eid
from cubicweb import ValidationError, RegistryException
from cubicweb.view import Component
from cubicweb.server.sources import datafeed
from cubicweb.server.hook import match_rtype
......@@ -326,10 +326,10 @@ class CWEntityXMLItemBuilder(Component):
item['cwtype'] = unicode(node.tag)
item.setdefault('cwsource', None)
try:
item['eid'] = typed_eid(item['eid'])
item['eid'] = int(item['eid'])
except KeyError:
# cw < 3.11 compat mode XXX
item['eid'] = typed_eid(node.find('eid').text)
item['eid'] = int(node.find('eid').text)
item['cwuri'] = node.find('cwuri').text
rels = {}
for child in node:
......
......@@ -26,7 +26,7 @@ __docformat__ = "restructuredtext en"
import re
from cubicweb import UnknownEid, typed_eid
from cubicweb import UnknownEid
from cubicweb.view import Component
......@@ -66,7 +66,7 @@ class ChangeStateTextParser(TextParser):
def parse(self, caller, text):
for trname, eid in self.instr_rgx.findall(text):
try:
entity = self._cw.entity_from_eid(typed_eid(eid))
entity = self._cw.entity_from_eid(int(eid))
except UnknownEid:
self.error("can't get entity with eid %s", eid)
continue
......
......@@ -64,7 +64,7 @@ from logilab.common.registry import yes
from rql import nodes, utils
from cubicweb import Unauthorized, typed_eid
from cubicweb import Unauthorized
from cubicweb.schema import display_name
from cubicweb.uilib import css_em_num_value
from cubicweb.utils import make_uid
......@@ -500,8 +500,7 @@ class VocabularyFacet(AbstractFacet):
return FacetVocabularyWidget
def get_selected(self):
return frozenset(typed_eid(eid)
for eid in self._cw.list_form_param(self.__regid__))
return frozenset(int(eid) for eid in self._cw.list_form_param(self.__regid__))
def get_widget(self):
"""Return the widget instance to use to display this facet.
......
......@@ -127,7 +127,7 @@ from logilab.mtconverter import xml_escape
from logilab.common.decorators import iclassmethod, cached
from logilab.common.deprecation import deprecated
from cubicweb import typed_eid, neg_role, uilib
from cubicweb import neg_role, uilib
from cubicweb.schema import display_name
from cubicweb.view import EntityView
from cubicweb.predicates import (
......@@ -415,7 +415,7 @@ def parse_relations_descr(rdescr):
subjs, rtype, objs = rstr.split(':')
for subj in subjs.split('_'):
for obj in objs.split('_'):
yield typed_eid(subj), rtype, typed_eid(obj)
yield int(subj), rtype, int(obj)
def delete_relations(req, rdefs):
"""delete relations from the repository"""
......@@ -460,12 +460,12 @@ def cancel_edition(self, errorurl):
def _add_pending(req, eidfrom, rel, eidto, kind):
key = 'pending_%s' % kind
pendings = req.session.data.setdefault(key, set())
pendings.add( (typed_eid(eidfrom), rel, typed_eid(eidto)) )
pendings.add( (int(eidfrom), rel, int(eidto)) )
def _remove_pending(req, eidfrom, rel, eidto, kind):
key = 'pending_%s' % kind
pendings = req.session.data[key]
pendings.remove( (typed_eid(eidfrom), rel, typed_eid(eidto)) )
pendings.remove( (int(eidfrom), rel, int(eidto)) )
@ajaxfunc(output_type='json')
def remove_pending_insert(self, (eidfrom, rel, eidto)):
......@@ -606,7 +606,7 @@ class GenericRelationsField(ff.Field):
for pendingid in pending_inserts:
eidfrom, rtype, eidto = pendingid.split(':')
pendingid = 'id' + pendingid
if typed_eid(eidfrom) == entity.eid: # subject
if int(eidfrom) == entity.eid: # subject
label = display_name(form._cw, rtype, 'subject',
entity.__regid__)
reid = eidto
......
......@@ -27,7 +27,7 @@ from warnings import warn
from logilab.common.deprecation import deprecated
from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
AuthenticationError, typed_eid, UndoTransactionException,
AuthenticationError, UndoTransactionException,
Forbidden)
from cubicweb.utils import json_dumps
from cubicweb.predicates import (authenticated_user, anonymous_user,
......@@ -176,7 +176,7 @@ class ViewController(Controller):
if not '__linkto' in req.form:
return
if eid is None:
eid = typed_eid(req.form['eid'])
eid = int(req.form['eid'])
for linkto in req.list_form_param('__linkto', pop=True):
rtype, eids, target = linkto.split(':')
assert target in ('subject', 'object')
......@@ -186,7 +186,7 @@ class ViewController(Controller):
else:
rql = 'SET Y %s X WHERE X eid %%(x)s, Y eid %%(y)s' % rtype
for teid in eids:
req.execute(rql, {'x': eid, 'y': typed_eid(teid)})
req.execute(rql, {'x': eid, 'y': int(teid)})
def _validation_error(req, ex):
......
......@@ -22,7 +22,7 @@ _ = unicode
from logilab.mtconverter import xml_escape
from cubicweb import Unauthorized, typed_eid
from cubicweb import Unauthorized
from cubicweb.predicates import is_instance, one_line_rset
from cubicweb.web import action, component, htmlwidgets, formwidgets as fw
from cubicweb.web.views import uicfg, primary
......@@ -137,4 +137,4 @@ class BookmarksBox(component.CtxComponent):
@ajaxfunc
def delete_bookmark(self, beid):
rql = 'DELETE B bookmarked_by U WHERE B eid %(b)s, U eid %(u)s'
self._cw.execute(rql, {'b': typed_eid(beid), 'u' : self._cw.user.eid})
self._cw.execute(rql, {'b': int(beid), 'u' : self._cw.user.eid})
......@@ -25,7 +25,7 @@ from logilab.common.deprecation import deprecated
from rql.utils import rqlvar_maker
from cubicweb import Binary, ValidationError, typed_eid
from cubicweb import Binary, ValidationError
from cubicweb.view import EntityAdapter, implements_adapter_compat
from cubicweb.predicates import is_instance
from cubicweb.web import (INTERNAL_FIELD_VALUE, RequestError, NothingToEdit,
......@@ -67,7 +67,7 @@ class IEditControlAdapter(EntityAdapter):
def valerror_eid(eid):
try:
return typed_eid(eid)
return int(eid)
except (ValueError, TypeError):
return eid
......@@ -217,7 +217,7 @@ class EditController(basecontrollers.ViewController):
todelete = self._cw.list_form_param('__delete', formparams, pop=True)
autoform.delete_relations(self._cw, todelete)
if '__cloned_eid' in formparams:
entity.copy_relations(typed_eid(formparams['__cloned_eid']))
entity.copy_relations(int(formparams['__cloned_eid']))
if is_main_entity: # only execute linkto for the main entity
self.execute_linkto(entity.eid)
return eid
......
......@@ -23,7 +23,6 @@ _ = unicode
from logilab.common.decorators import cached
from logilab.mtconverter import xml_escape
from cubicweb import typed_eid
from cubicweb.view import EntityView, StartupView
from cubicweb.predicates import (one_line_rset, non_final_entity,
match_search_state)
......@@ -53,7 +52,7 @@ class SearchForAssociationView(EntityView):
def filter_box_context_info(self):
entity = self.cw_rset.get_entity(0, 0)
role, eid, rtype, etype = self._cw.search_state[1]
assert entity.eid == typed_eid(eid)
assert entity.eid == int(eid)
# the default behaviour is to fetch all unrelated entities and display
# them. Use fetch_order and not fetch_unrelated_order as sort method
# since the latter is mainly there to select relevant items in the combo
......
......@@ -51,7 +51,7 @@ from logilab.common.compat import any
from logilab.common.textutils import splitstrip
from logilab.common.deprecation import deprecated
from cubicweb import ValidationError, typed_eid
from cubicweb import ValidationError
from cubicweb.utils import support_args
from cubicweb.predicates import non_final_entity, match_kwargs, one_line_rset
from cubicweb.web import RequestError, ProcessFormError
......@@ -404,7 +404,7 @@ class EntityFieldsForm(FieldsForm):
linked_to = {}
for linkto in self._cw.list_form_param('__linkto'):
ltrtype, eid, ltrole = linkto.split(':')
linked_to.setdefault((ltrtype, ltrole), []).append(typed_eid(eid))
linked_to.setdefault((ltrtype, ltrole), []).append(int(eid))
return linked_to
def session_key(self):
......@@ -436,7 +436,7 @@ class EntityFieldsForm(FieldsForm):
# created entity)
assert eid or eid == 0, repr(eid) # 0 is a valid eid
try:
return typed_eid(eid)
return int(eid)
except ValueError:
try:
return self._cw.data['eidmap'][eid]
......
......@@ -29,7 +29,7 @@ from rql import RQLSyntaxError, BadRQLQuery, parse
from rql.utils import rqlvar_maker
from rql.nodes import Relation
from cubicweb import Unauthorized, typed_eid
from cubicweb import Unauthorized
from cubicweb.view import Component
from cubicweb.web.views.ajaxcontroller import ajaxfunc
......@@ -254,7 +254,7 @@ class QSPreProcessor(BaseQueryProcessor):
"""
# if this is an integer, then directly go to eid
try:
eid = typed_eid(word)
eid = int(word)
return 'Any X WHERE X eid %(x)s', {'x': eid}, 'x'
except ValueError:
etype = self._get_entity_type(word)
......
......@@ -29,7 +29,7 @@ from logilab.mtconverter import xml_escape
from logilab.common.deprecation import deprecated, class_renamed
from logilab.common.decorators import cached
from cubicweb import neg_role, typed_eid
from cubicweb import neg_role
from cubicweb.schema import display_name
from cubicweb.utils import json, json_dumps
from cubicweb.predicates import non_final_entity, match_kwargs
......@@ -402,7 +402,7 @@ def reledit_form(self):
req = self._cw
args = dict((x, req.form[x])
for x in ('formid', 'rtype', 'role', 'reload', 'action'))
rset = req.eid_rset(typed_eid(self._cw.form['eid']))
rset = req.eid_rset(int(self._cw.form['eid']))
try:
args['reload'] = json.loads(args['reload'])
except ValueError: # not true/false, an absolute url
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment