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.
--- a/__init__.py Wed Mar 20 17:58:14 2013 +0100
+++ b/__init__.py Tue Mar 12 12:50:05 2013 +0100
@@ -38,10 +38,10 @@
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 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
--- a/entities/__init__.py Wed Mar 20 17:58:14 2013 +0100
+++ b/entities/__init__.py Tue Mar 12 12:50:05 2013 +0100
@@ -24,7 +24,7 @@
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
--- a/entity.py Wed Mar 20 17:58:14 2013 +0100
+++ b/entity.py Tue Mar 12 12:50:05 2013 +0100
@@ -33,7 +33,7 @@
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 @@
meaning that the entity has to be created
"""
try:
- typed_eid(self.eid)
+ int(self.eid)
return True
except (ValueError, TypeError):
return False
--- a/req.py Wed Mar 20 17:58:14 2013 +0100
+++ b/req.py Tue Mar 12 12:50:05 2013 +0100
@@ -29,7 +29,7 @@
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 @@
(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},
--- a/rqlrewrite.py Wed Mar 20 17:58:14 2013 +0100
+++ b/rqlrewrite.py Tue Mar 12 12:50:05 2013 +0100
@@ -30,7 +30,7 @@
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 @@
vi = {}
self.varinfos.append(vi)
try:
- vi['const'] = typed_eid(selectvar)
+ vi['const'] = int(selectvar)
vi['rhs_rels'] = vi['lhs_rels'] = {}
except ValueError:
try:
--- a/server/querier.py Wed Mar 20 17:58:14 2013 +0100
+++ b/server/querier.py Tue Mar 12 12:50:05 2013 +0100
@@ -31,7 +31,7 @@
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 @@
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 @@
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:
--- a/server/repository.py Wed Mar 20 17:58:14 2013 +0100
+++ b/server/repository.py Tue Mar 12 12:50:05 2013 +0100
@@ -50,7 +50,7 @@
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 @@
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 @@
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 @@
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):
--- a/server/schemaserial.py Wed Mar 20 17:58:14 2013 +0100
+++ b/server/schemaserial.py Tue Mar 12 12:50:05 2013 +0100
@@ -26,7 +26,7 @@
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 @@
if not value:
continue
try:
- eid = typed_eid(value)
+ eid = int(value)
except ValueError:
print 'eid should be an integer'
continue
--- a/server/ssplanner.py Wed Mar 20 17:58:14 2013 +0100
+++ b/server/ssplanner.py Tue Mar 12 12:50:05 2013 +0100
@@ -22,7 +22,7 @@
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 @@
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 @@
"""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 @@
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:
--- a/sobjects/cwxmlparser.py Wed Mar 20 17:58:14 2013 +0100
+++ b/sobjects/cwxmlparser.py Tue Mar 12 12:50:05 2013 +0100
@@ -42,7 +42,7 @@
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 @@
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:
--- a/sobjects/textparsers.py Wed Mar 20 17:58:14 2013 +0100
+++ b/sobjects/textparsers.py Tue Mar 12 12:50:05 2013 +0100
@@ -26,7 +26,7 @@
import re
-from cubicweb import UnknownEid, typed_eid
+from cubicweb import UnknownEid
from cubicweb.view import Component
@@ -66,7 +66,7 @@
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
--- a/web/facet.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/facet.py Tue Mar 12 12:50:05 2013 +0100
@@ -64,7 +64,7 @@
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 @@
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.
--- a/web/views/autoform.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/autoform.py Tue Mar 12 12:50:05 2013 +0100
@@ -127,7 +127,7 @@
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 @@
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 _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 @@
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
--- a/web/views/basecontrollers.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/basecontrollers.py Tue Mar 12 12:50:05 2013 +0100
@@ -27,7 +27,7 @@
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 @@
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 @@
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):
--- a/web/views/bookmark.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/bookmark.py Tue Mar 12 12:50:05 2013 +0100
@@ -22,7 +22,7 @@
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 @@
@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})
--- a/web/views/editcontroller.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/editcontroller.py Tue Mar 12 12:50:05 2013 +0100
@@ -25,7 +25,7 @@
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 @@
def valerror_eid(eid):
try:
- return typed_eid(eid)
+ return int(eid)
except (ValueError, TypeError):
return eid
@@ -217,7 +217,7 @@
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
--- a/web/views/editviews.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/editviews.py Tue Mar 12 12:50:05 2013 +0100
@@ -23,7 +23,6 @@
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 @@
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
--- a/web/views/forms.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/forms.py Tue Mar 12 12:50:05 2013 +0100
@@ -51,7 +51,7 @@
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 @@
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 @@
# 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]
--- a/web/views/magicsearch.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/magicsearch.py Tue Mar 12 12:50:05 2013 +0100
@@ -29,7 +29,7 @@
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 @@
"""
# 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)
--- a/web/views/reledit.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/reledit.py Tue Mar 12 12:50:05 2013 +0100
@@ -29,7 +29,7 @@
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 @@
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
--- a/web/views/urlpublishing.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/urlpublishing.py Tue Mar 12 12:50:05 2013 +0100
@@ -59,7 +59,7 @@
from rql import TypeResolverException
-from cubicweb import RegistryException, typed_eid
+from cubicweb import RegistryException
from cubicweb.web import NotFound, Redirect, component
@@ -165,7 +165,7 @@
if len(parts) != 1:
raise PathDontMatch()
try:
- rset = req.execute('Any X WHERE X eid %(x)s', {'x': typed_eid(parts[0])})
+ rset = req.execute('Any X WHERE X eid %(x)s', {'x': int(parts[0])})
except ValueError:
raise PathDontMatch()
if rset.rowcount == 0:
@@ -222,7 +222,7 @@
'x', 'Substitute')
if attrname == 'eid':
try:
- rset = req.execute(st.as_string(), {'x': typed_eid(value)})
+ rset = req.execute(st.as_string(), {'x': int(value)})
except (ValueError, TypeResolverException):
# conflicting eid/type
raise PathDontMatch()
--- a/web/views/urlrewrite.py Wed Mar 20 17:58:14 2013 +0100
+++ b/web/views/urlrewrite.py Tue Mar 12 12:50:05 2013 +0100
@@ -19,7 +19,6 @@
import re
-from cubicweb import typed_eid
from cubicweb.uilib import domid
from cubicweb.appobject import AppObject
@@ -186,7 +185,7 @@
except KeyError:
kwargs[key] = value
if cachekey is not None and key in cachekey:
- kwargs[key] = typed_eid(value)
+ kwargs[key] = int(value)
if setuser:
kwargs['u'] = req.user.eid
for param in rqlformparams: