--- a/cubicweb/server/schemaserial.py Fri Apr 05 17:21:14 2019 +0200
+++ b/cubicweb/server/schemaserial.py Fri Apr 05 17:58:19 2019 +0200
@@ -17,14 +17,10 @@
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""functions for schema / permissions (de)serialization using RQL"""
-from __future__ import print_function
-
import json
import sys
import sqlite3
-from six import PY2, text_type, string_types
-
from logilab.common.shellutils import ProgressBar, DummyProgressBar
from yams import BadSchemaDefinition, schema as schemamod, buildobjs as ybo, constraints
@@ -378,7 +374,7 @@
cstrtypemap = {}
rql = 'INSERT CWConstraintType X: X name %(ct)s'
for cstrtype in CONSTRAINTS:
- cstrtypemap[cstrtype] = execute(rql, {'ct': text_type(cstrtype)},
+ cstrtypemap[cstrtype] = execute(rql, {'ct': cstrtype},
build_descr=False)[0][0]
pb.update()
# serialize relations
@@ -483,7 +479,7 @@
for i, name in enumerate(unique_together):
rschema = eschema.schema.rschema(name)
rtype = 'T%d' % i
- substs[rtype] = text_type(rschema.type)
+ substs[rtype] = rschema.type
relations.append('C relations %s' % rtype)
restrictions.append('%(rtype)s name %%(%(rtype)s)s' % {'rtype': rtype})
relations = ', '.join(relations)
@@ -494,18 +490,10 @@
def _ervalues(erschema):
- try:
- type_ = text_type(erschema.type)
- except UnicodeDecodeError as e:
- raise Exception("can't decode %s [was %s]" % (erschema.type, e))
- try:
- desc = text_type(erschema.description) or u''
- except UnicodeDecodeError as e:
- raise Exception("can't decode %s [was %s]" % (erschema.description, e))
return {
- 'name': type_,
+ 'name': erschema.type,
'final': erschema.final,
- 'description': desc,
+ 'description': erschema.description,
}
# rtype serialization
@@ -531,10 +519,7 @@
values['final'] = rschema.final
values['symmetric'] = rschema.symmetric
values['inlined'] = rschema.inlined
- if PY2 and isinstance(rschema.fulltext_container, str):
- values['fulltext_container'] = unicode(rschema.fulltext_container)
- else:
- values['fulltext_container'] = rschema.fulltext_container
+ values['fulltext_container'] = rschema.fulltext_container
relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
return relations, values
@@ -547,7 +532,7 @@
def crschema_relations_values(crschema):
values = _ervalues(crschema)
- values['rule'] = text_type(crschema.rule)
+ values['rule'] = crschema.rule
# XXX why oh why?
del values['final']
relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
@@ -593,8 +578,6 @@
value = bool(value)
elif prop == 'ordernum':
value = int(value)
- elif PY2 and isinstance(value, str):
- value = unicode(value)
if value is not None and prop == 'default':
value = Binary.zpickle(value)
values[amap.get(prop, prop)] = value
@@ -606,7 +589,7 @@
def constraints2rql(cstrtypemap, constraints, rdefeid=None):
for constraint in constraints:
values = {'ct': cstrtypemap[constraint.type()],
- 'value': text_type(constraint.serialize()),
+ 'value': constraint.serialize(),
'x': rdefeid} # when not specified, will have to be set by the caller
yield 'INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE \
CT eid %(ct)s, EDEF eid %(x)s', values
@@ -625,7 +608,7 @@
# may occurs when modifying persistent schema
continue
for group_or_rqlexpr in grantedto:
- if isinstance(group_or_rqlexpr, string_types):
+ if isinstance(group_or_rqlexpr, str):
# group
try:
yield ('SET X %s_permission Y WHERE Y eid %%(g)s, X eid %%(x)s' % action,
@@ -639,9 +622,9 @@
rqlexpr = group_or_rqlexpr
yield ('INSERT RQLExpression E: E expression %%(e)s, E exprtype %%(t)s, '
'E mainvars %%(v)s, X %s_permission E WHERE X eid %%(x)s' % action,
- {'e': text_type(rqlexpr.expression),
- 'v': text_type(','.join(sorted(rqlexpr.mainvars))),
- 't': text_type(rqlexpr.__class__.__name__)})
+ {'e': rqlexpr.expression,
+ 'v': ','.join(sorted(rqlexpr.mainvars)),
+ 't': rqlexpr.__class__.__name__})
# update functions
@@ -653,7 +636,7 @@
def updaterschema2rql(rschema, eid):
if rschema.rule:
yield ('SET X rule %(r)s WHERE X eid %(x)s',
- {'x': eid, 'r': text_type(rschema.rule)})
+ {'x': eid, 'r': rschema.rule})
else:
relations, values = rschema_relations_values(rschema)
values['x'] = eid