Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
c5ad4e650499
Commit
4c602019
authored
Jul 07, 2021
by
Laurent Peuch
Browse files
style: hg format-source with pyupgrade took
parent
0d87c67136af
Changes
213
Expand all
Hide whitespace changes
Inline
Side-by-side
.hg-format-source
View file @
c5ad4e65
This diff is collapsed.
Click to expand it.
cubicweb/__init__.py
View file @
c5ad4e65
...
...
@@ -190,7 +190,7 @@ def target(obj):
return
neg_role
(
obj
.
role
)
class
CubicWebEventManager
(
object
)
:
class
CubicWebEventManager
:
"""simple event / callback manager.
Typical usage to register a callback::
...
...
cubicweb/_exceptions.py
View file @
c5ad4e65
...
...
@@ -117,7 +117,7 @@ class ViolatedConstraint(RepositoryError):
"constraint '%s' is being violated by the query '%s'. "
"You can run the inverted constraint on the database to list the problematic rows."
)
%
(
cstrname
,
query
)
super
(
ViolatedConstraint
,
self
).
__init__
(
message
)
super
().
__init__
(
message
)
# security exceptions #########################################################
...
...
@@ -214,7 +214,7 @@ class UndoTransactionException(QueryError):
msg
=
"The following error(s) occurred while undoing transaction #%d : %s"
def
__init__
(
self
,
txuuid
,
errors
):
super
(
UndoTransactionException
,
self
).
__init__
(
txuuid
,
errors
)
super
().
__init__
(
txuuid
,
errors
)
self
.
txuuid
=
txuuid
self
.
errors
=
errors
...
...
cubicweb/_gcdebug.py
View file @
c5ad4e65
...
...
@@ -76,7 +76,7 @@ def gc_info(
counters
[
cls
.
__name__
]
=
1
elif
not
isinstance
(
obj
,
ignoreclasses
):
try
:
key
=
"%s.%s"
%
(
obj
.
__class__
.
__module__
,
obj
.
__class__
.
__name__
)
key
=
f
"
{
obj
.
__class__
.
__module__
}
.
{
obj
.
__class__
.
__name__
}
"
except
AttributeError
:
key
=
str
(
obj
)
try
:
...
...
@@ -93,10 +93,10 @@ def referrers(obj, showobj=False, maxlevel=1):
objreferrers
=
_referrers
(
obj
,
maxlevel
)
try
:
return
sorted
(
set
(
{
(
type
(
x
),
showobj
and
x
or
getattr
(
x
,
"__name__"
,
"%#x"
%
id
(
x
)))
for
x
in
objreferrers
)
}
)
except
TypeError
:
s
=
set
()
...
...
cubicweb/appobject.py
View file @
c5ad4e65
...
...
@@ -96,7 +96,7 @@ class AppObject(RegistrableObject):
return
cls
def
__init__
(
self
,
req
,
**
extra
):
super
(
AppObject
,
self
).
__init__
()
super
().
__init__
()
self
.
_cw
=
req
try
:
self
.
cw_rset
=
extra
.
pop
(
"rset"
)
...
...
@@ -128,7 +128,7 @@ class AppObject(RegistrableObject):
"""return cw property key for the property of the given id for this
class
"""
return
"%s.%s.%s"
%
(
cls
.
__registry__
,
cls
.
__regid__
,
propid
)
return
f
"
{
cls
.
__registry__
}
.
{
cls
.
__regid__
}
.
{
propid
}
"
def
cw_propval
(
self
,
propid
):
"""return cw property value associated to key
...
...
cubicweb/cwconfig.py
View file @
c5ad4e65
# -*- coding: utf-8 -*-
# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr/ -- mailto:contact@logilab.fr
#
...
...
@@ -788,7 +787,7 @@ this option is set to yes",
modnames
.
append
((
"cubicweb"
,
"cubicweb.schemas."
+
name
))
for
cube
in
reversed
(
self
.
cubes
()):
for
modname
,
filepath
in
_expand_modname
(
"{
0
}.schema"
.
format
(
_cube_pkgname
(
cube
)),
recursive
=
False
"{}.schema"
.
format
(
_cube_pkgname
(
cube
)),
recursive
=
False
):
modnames
.
append
((
cube
,
modname
))
if
self
.
apphome
:
...
...
cubicweb/cwvreg.py
View file @
c5ad4e65
...
...
@@ -82,7 +82,7 @@ class CWRegistry(Registry):
"""
:param vreg: the :py:class:`CWRegistryStore` managing this registry.
"""
super
(
CWRegistry
,
self
).
__init__
(
True
)
super
().
__init__
(
True
)
self
.
vreg
=
vreg
self
.
add_select_best_listener
(
self
.
_emit_registry_debug_information
)
...
...
@@ -132,7 +132,7 @@ class ETypeRegistry(CWRegistry):
def
initialization_completed
(
self
):
"""on registration completed, clear etype_class internal cache"""
super
(
ETypeRegistry
,
self
).
initialization_completed
()
super
().
initialization_completed
()
# clear etype cache if you don't want to run into deep weirdness
self
.
clear_caches
()
# rebuild all classes to avoid potential memory fragmentation
...
...
@@ -149,7 +149,7 @@ class ETypeRegistry(CWRegistry):
)
return
kwargs
[
"clear"
]
=
True
super
(
ETypeRegistry
,
self
).
register
(
obj
,
**
kwargs
)
super
().
register
(
obj
,
**
kwargs
)
def
iter_classes
(
self
):
for
etype
in
self
.
vreg
.
schema
.
entities
():
...
...
@@ -292,7 +292,7 @@ class CtxComponentsRegistry(CWRegistry):
try
:
cached
=
cache
.
__components_cache
except
AttributeError
:
ctxcomps
=
super
(
CtxComponentsRegistry
,
self
).
poss_visible_objects
(
ctxcomps
=
super
().
poss_visible_objects
(
*
args
,
**
kwargs
)
if
cache
is
None
:
...
...
@@ -358,7 +358,7 @@ class CWRegistryStore(RegistryStore):
if
initlog
:
# first init log service
config
.
init_log
()
super
(
CWRegistryStore
,
self
).
__init__
(
config
.
debugmode
)
super
().
__init__
(
config
.
debugmode
)
self
.
config
=
config
# need to clean sys.path this to avoid import confusion pb (i.e. having
# the same module loaded as 'cubicweb.web.views' subpackage and as
...
...
@@ -404,7 +404,7 @@ class CWRegistryStore(RegistryStore):
def
reset
(
self
):
CW_EVENT_MANAGER
.
emit
(
"before-registry-reset"
,
self
)
super
(
CWRegistryStore
,
self
).
reset
()
super
().
reset
()
self
.
_needs_appobject
=
{}
# two special registries, propertydefs which care all the property
# definitions, and propertyvals which contains values for those
...
...
@@ -417,14 +417,14 @@ class CWRegistryStore(RegistryStore):
CW_EVENT_MANAGER
.
emit
(
"after-registry-reset"
,
self
)
def
register_all
(
self
,
objects
,
modname
,
butclasses
=
()):
butclasses
=
set
(
related_appobject
(
obj
)
for
obj
in
butclasses
)
butclasses
=
{
related_appobject
(
obj
)
for
obj
in
butclasses
}
objects
=
[
related_appobject
(
obj
)
for
obj
in
objects
]
super
(
CWRegistryStore
,
self
).
register_all
(
objects
,
modname
,
butclasses
)
super
().
register_all
(
objects
,
modname
,
butclasses
)
def
register_and_replace
(
self
,
obj
,
replaced
):
obj
=
related_appobject
(
obj
)
replaced
=
related_appobject
(
replaced
)
super
(
CWRegistryStore
,
self
).
register_and_replace
(
obj
,
replaced
)
super
().
register_and_replace
(
obj
,
replaced
)
def
set_schema
(
self
,
schema
):
"""set instance'schema and load application objects"""
...
...
@@ -505,7 +505,7 @@ class CWRegistryStore(RegistryStore):
self
.
currently_loading_cube
=
modpath
[
modpath
.
index
(
"cubes"
)
+
1
]
except
ValueError
:
self
.
currently_loading_cube
=
"cubicweb"
return
super
(
CWRegistryStore
,
self
).
load_file
(
filepath
,
modname
)
return
super
().
load_file
(
filepath
,
modname
)
def
_set_schema
(
self
,
schema
):
"""set instance'schema"""
...
...
@@ -531,7 +531,7 @@ class CWRegistryStore(RegistryStore):
previously unregistered.
"""
obj
=
related_appobject
(
obj
)
super
(
CWRegistryStore
,
self
).
register
(
obj
,
*
args
,
**
kwargs
)
super
().
register
(
obj
,
*
args
,
**
kwargs
)
depends_on
=
require_appobject
(
obj
)
if
depends_on
is
not
None
:
self
.
_needs_appobject
[
obj
]
=
depends_on
...
...
@@ -565,7 +565,7 @@ class CWRegistryStore(RegistryStore):
regname
,
)
self
.
unregister
(
obj
)
super
(
CWRegistryStore
,
self
).
initialization_completed
()
super
().
initialization_completed
()
if
"uicfg"
in
self
:
# 'uicfg' is not loaded in a pure repository mode
for
rtags
in
self
[
"uicfg"
].
values
():
for
rtag
in
rtags
:
...
...
cubicweb/dataimport/importer.py
View file @
c5ad4e65
...
...
@@ -75,7 +75,7 @@ def use_extid_as_cwuri(extid2eid):
cwuri
=
extentity
.
extid
if
isinstance
(
cwuri
,
bytes
):
cwuri
=
cwuri
.
decode
(
"utf-8"
)
extentity
.
values
.
setdefault
(
"cwuri"
,
set
([
cwuri
])
)
extentity
.
values
.
setdefault
(
"cwuri"
,
{
cwuri
}
)
yield
extentity
return
use_extid_as_cwuri_filter
...
...
@@ -111,11 +111,11 @@ def drop_extra_values(extentities, schema, import_log):
%
(
rtype
,
values
),
path
=
extentity
.
extid
,
)
entity_dict
[
key
]
=
set
([
entity_dict
[
key
].
pop
()
])
entity_dict
[
key
]
=
{
entity_dict
[
key
].
pop
()
}
yield
extentity
class
RelationMapping
(
object
)
:
class
RelationMapping
:
"""Read-only mapping from relation type to set of related (subject, object) eids.
If `source` is specified, only returns relations implying entities from
...
...
@@ -133,10 +133,10 @@ class RelationMapping(object):
def
__getitem__
(
self
,
rtype
):
"""Return a set of (subject, object) eids already related by `rtype`"""
rql
=
self
.
_rql_template
%
rtype
return
set
(
tuple
(
x
)
for
x
in
self
.
cnx
.
execute
(
rql
,
self
.
_kwargs
)
)
return
{
tuple
(
x
)
for
x
in
self
.
cnx
.
execute
(
rql
,
self
.
_kwargs
)
}
class
ExtEntity
(
object
)
:
class
ExtEntity
:
"""Transitional representation of an entity for use in data importer.
An external entity has the following properties:
...
...
@@ -170,7 +170,7 @@ class ExtEntity(object):
self
.
_schema
=
None
def
__repr__
(
self
):
return
"<
%s %s %s>"
%
(
self
.
etype
,
self
.
extid
,
self
.
values
)
return
f
"<
{
self
.
etype
}
{
self
.
extid
}
{
self
.
values
}
>"
def
iter_rdefs
(
self
):
"""Yield (key, rtype, role) defined in `.values` dict, with:
...
...
@@ -217,7 +217,7 @@ class ExtEntity(object):
if
rschema
.
final
or
(
rschema
.
inlined
and
role
==
"subject"
):
assert
(
len
(
entity_dict
[
key
])
<=
1
),
"more than one value for
%s: %s (%s)"
%
(
),
"more than one value for
{}: {} ({})"
.
format
(
rtype
,
entity_dict
[
key
],
self
.
extid
,
...
...
@@ -282,14 +282,14 @@ class ExtEntity(object):
rschema
=
schema
.
rschema
(
rtype
)
if
not
rschema
.
final
:
if
entity_dict
[
rtype
]
not
in
extid2eid
:
return
"inlined relation
%s
is not present (
%s)"
%
(
return
"inlined relation
{}
is not present (
{})"
.
format
(
rtype
,
entity_dict
[
rtype
],
)
raise
AssertionError
(
"this external entity seems actually ready for insertion"
)
class
ExtEntitiesImporter
(
object
)
:
class
ExtEntitiesImporter
:
"""This class is responsible for importing externals entities, that is instances of
:class:`ExtEntity`, into CubicWeb entities.
...
...
@@ -434,7 +434,7 @@ class ExtEntitiesImporter(object):
missing_relations
=
[]
for
rtype
,
relations
in
deferred
.
items
():
self
.
import_log
.
record_debug
(
"importing
%s %s
relations"
%
(
len
(
relations
),
rtype
)
"importing
{} {}
relations"
.
format
(
len
(
relations
),
rtype
)
)
symmetric
=
rschema
(
rtype
).
symmetric
existing
=
self
.
existing_relations
[
rtype
]
...
...
@@ -479,7 +479,7 @@ class ExtEntitiesImporter(object):
raise
Exception
(
"
\n
"
.
join
(
msgs
))
class
SimpleImportLog
(
object
)
:
class
SimpleImportLog
:
"""Fake CWDataImport log using a simple text format.
Useful to display logs in the UI instead of storing them to the
...
...
@@ -506,7 +506,7 @@ class SimpleImportLog(object):
self
.
_log
(
logging
.
FATAL
,
msg
,
path
,
line
)
def
_log
(
self
,
severity
,
msg
,
path
,
line
):
encodedmsg
=
"
%s
\t
%s
\t
%s
\t
%s"
%
(
severity
,
self
.
filename
,
line
or
""
,
msg
)
encodedmsg
=
"
{}
\t
{}
\t
{}
\t
{}"
.
format
(
severity
,
self
.
filename
,
line
or
""
,
msg
)
self
.
logs
.
append
(
encodedmsg
)
...
...
@@ -514,10 +514,10 @@ class HTMLImportLog(SimpleImportLog):
"""Fake CWDataImport log using a simple HTML format."""
def
__init__
(
self
,
filename
):
super
(
HTMLImportLog
,
self
).
__init__
(
xml_escape
(
filename
))
super
().
__init__
(
xml_escape
(
filename
))
def
_log
(
self
,
severity
,
msg
,
path
,
line
):
encodedmsg
=
"
%s
\t
%s
\t
%s
\t
%s<br/>"
%
(
encodedmsg
=
"
{}
\t
{}
\t
{}
\t
{}<br/>"
.
format
(
severity
,
self
.
filename
,
line
or
""
,
...
...
cubicweb/dataimport/massive_store.py
View file @
c5ad4e65
# coding: utf-8
# copyright 2015-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr/ -- mailto:contact@logilab.fr
#
...
...
cubicweb/dataimport/pgstore.py
View file @
c5ad4e65
...
...
@@ -97,7 +97,7 @@ def _execmany_thread(
osp
.
join
(
dump_output_dir
,
"%s.pickle"
%
filename
),
"wb"
)
as
fobj
:
pickle
.
dump
(
pdata
,
fobj
)
except
I
OError
:
except
O
S
Error
:
print
(
"ERROR while pickling in"
,
dump_output_dir
,
...
...
@@ -139,7 +139,7 @@ def _copyfrom_buffer_convert_datetime(value, **opts):
'''Convert date into "YYYY-MM-DD HH:MM:SS.UUUUUU"'''
# Do not use strftime, as it yields issue with date < 1900
# (http://bugs.python.org/issue1777412)
return
"
%s %s"
%
(
return
"
{} {}"
.
format
(
_copyfrom_buffer_convert_date
(
value
,
**
opts
),
_copyfrom_buffer_convert_time
(
value
,
**
opts
),
)
...
...
@@ -195,7 +195,7 @@ def _create_copyfrom_buffer(data, columns=None, **convert_opts):
value
=
row
[
col
]
except
KeyError
:
warnings
.
warn
(
"Column
%s
is not accessible in row
%s"
%
(
col
,
row
)
,
RuntimeWarning
f
"Column
{
col
}
is not accessible in row
{
row
}
"
,
RuntimeWarning
)
# XXX 'value' set to None so that the import does not end in
# error.
...
...
@@ -221,7 +221,7 @@ def _create_copyfrom_buffer(data, columns=None, **convert_opts):
###########################################################################
class
SQLGenSourceWrapper
(
object
)
:
class
SQLGenSourceWrapper
:
def
__init__
(
self
,
system_source
,
schema
,
dump_output_dir
=
None
):
self
.
system_source
=
system_source
# Explicitely backport attributes from system source
...
...
cubicweb/dataimport/test/test_massive_store.py
View file @
c5ad4e65
# -*- coding: utf-8 -*-
# copyright 2013-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr -- mailto:contact@logilab.fr
#
...
...
@@ -37,7 +36,7 @@ def tearDownModule(*args):
def
all_indexes
(
cnx
):
crs
=
cnx
.
system_sql
(
"SELECT indexname FROM pg_indexes"
)
return
set
(
r
[
0
]
for
r
in
crs
.
fetchall
()
)
return
{
r
[
0
]
for
r
in
crs
.
fetchall
()
}
class
MassiveObjectStoreWithCustomMDGenStoreTC
(
...
...
cubicweb/dataimport/test/test_pgstore.py
View file @
c5ad4e65
# coding: utf-8
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr/ -- mailto:contact@logilab.fr
#
...
...
cubicweb/dataimport/test/unittest_importer.py
View file @
c5ad4e65
# -*- coding: utf-8 -*-
# copyright 2015-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr -- mailto:contact@logilab.fr
#
...
...
@@ -39,7 +38,7 @@ class RelationMappingTC(CubicWebTC):
cnx
.
commit
()
mapping
=
RelationMapping
(
cnx
)
self
.
assertEqual
(
mapping
[
"connait"
],
set
([
(
bob_eid
,
alice_eid
),
(
alice_eid
,
bob_eid
)
])
mapping
[
"connait"
],
{
(
bob_eid
,
alice_eid
),
(
alice_eid
,
bob_eid
)
}
)
def
test_with_source
(
self
):
...
...
@@ -49,7 +48,7 @@ class RelationMappingTC(CubicWebTC):
cnx
.
commit
()
mapping
=
RelationMapping
(
cnx
,
cnx
.
find
(
"CWSource"
,
name
=
"system"
).
one
())
self
.
assertEqual
(
mapping
[
"connait"
],
set
([
(
bob_eid
,
alice_eid
),
(
alice_eid
,
bob_eid
)
])
mapping
[
"connait"
],
{
(
bob_eid
,
alice_eid
),
(
alice_eid
,
bob_eid
)
}
)
...
...
@@ -62,7 +61,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
personne
=
ExtEntity
(
"Personne"
,
1
,
{
"nom"
:
set
([
"de la lune"
])
,
"prenom"
:
set
([
"Jean"
])
}
"Personne"
,
1
,
{
"nom"
:
{
"de la lune"
}
,
"prenom"
:
{
"Jean"
}
}
)
importer
.
import_entities
([
personne
])
cnx
.
commit
()
...
...
@@ -75,7 +74,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
personne
=
ExtEntity
(
"Personne"
,
1
,
{
"photo"
:
set
([
b
"poilu"
])
,
"nom"
:
set
([
"alf"
])
}
"Personne"
,
1
,
{
"photo"
:
{
b
"poilu"
}
,
"nom"
:
{
"alf"
}
}
)
importer
.
import_entities
([
personne
])
cnx
.
commit
()
...
...
@@ -88,7 +87,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
# Use a list to put a Binary in "values" (since Binary is not
# hashable, a set cannot be used).
personne
=
ExtEntity
(
"Personne"
,
1
,
{
"photo"
:
[
Binary
(
b
"poilu"
)],
"nom"
:
set
([
"alf"
])
}
"Personne"
,
1
,
{
"photo"
:
[
Binary
(
b
"poilu"
)],
"nom"
:
{
"alf"
}
}
)
importer
.
import_entities
([
personne
])
cnx
.
commit
()
...
...
@@ -99,7 +98,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
"""Check import of ext entity with missing required attribute"""
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
tag
=
ExtEntity
(
"Personne"
,
2
,
{
"prenom"
:
set
([
"Jean"
])
})
tag
=
ExtEntity
(
"Personne"
,
2
,
{
"prenom"
:
{
"Jean"
}
})
self
.
assertRaises
(
ValidationError
,
importer
.
import_entities
,
[
tag
])
def
test_import_inlined_relation
(
self
):
...
...
@@ -107,9 +106,9 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
richelieu
=
ExtEntity
(
"Personne"
,
3
,
{
"nom"
:
set
([
"Richelieu"
])
,
"enfant"
:
set
([
4
])
}
"Personne"
,
3
,
{
"nom"
:
{
"Richelieu"
}
,
"enfant"
:
{
4
}
}
)
athos
=
ExtEntity
(
"Personne"
,
4
,
{
"nom"
:
set
([
"Athos"
])
})
athos
=
ExtEntity
(
"Personne"
,
4
,
{
"nom"
:
{
"Athos"
}
})
importer
.
import_entities
([
athos
,
richelieu
])
cnx
.
commit
()
rset
=
cnx
.
execute
(
'Any X WHERE X is Personne, X nom "Richelieu"'
)
...
...
@@ -121,9 +120,9 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
richelieu
=
ExtEntity
(
"Personne"
,
5
,
{
"nom"
:
set
([
"Richelieu"
])
,
"connait"
:
set
([
6
])
}
"Personne"
,
5
,
{
"nom"
:
{
"Richelieu"
}
,
"connait"
:
{
6
}
}
)
athos
=
ExtEntity
(
"Personne"
,
6
,
{
"nom"
:
set
([
"Athos"
])
})
athos
=
ExtEntity
(
"Personne"
,
6
,
{
"nom"
:
{
"Athos"
}
})
importer
.
import_entities
([
athos
,
richelieu
])
cnx
.
commit
()
rset
=
cnx
.
execute
(
'Any X WHERE X is Personne, X nom "Richelieu"'
)
...
...
@@ -138,7 +137,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
richelieu
=
ExtEntity
(
"Personne"
,
7
,
{
"nom"
:
set
([
"Richelieu"
])
,
"enfant"
:
set
([
8
])
}
"Personne"
,
7
,
{
"nom"
:
{
"Richelieu"
}
,
"enfant"
:
{
8
}
}
)
self
.
assertRaises
(
Exception
,
importer
.
import_entities
,
[
richelieu
])
cnx
.
commit
()
...
...
@@ -150,7 +149,7 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
richelieu
=
ExtEntity
(
"Personne"
,
9
,
{
"nom"
:
set
([
"Richelieu"
])
,
"connait"
:
set
([
10
])
}
"Personne"
,
9
,
{
"nom"
:
{
"Richelieu"
}
,
"connait"
:
{
10
}
}
)
self
.
assertRaises
(
Exception
,
importer
.
import_entities
,
[
richelieu
])
cnx
.
commit
()
...
...
@@ -164,9 +163,9 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
richelieu
=
ExtEntity
(
"Personne"
,
3
,
{
"nom"
:
set
([
"Richelieu"
])
,
"enfant"
:
set
([
4
])
}
"Personne"
,
3
,
{
"nom"
:
{
"Richelieu"
}
,
"enfant"
:
{
4
}
}
)
athos
=
ExtEntity
(
"Personne"
,
4
,
{
"nom"
:
set
([
"Athos"
])
})
athos
=
ExtEntity
(
"Personne"
,
4
,
{
"nom"
:
{
"Athos"
}
})
importer
.
import_entities
([
richelieu
,
athos
])
cnx
.
commit
()
rset
=
cnx
.
execute
(
'Any X WHERE X is Personne, X nom "Richelieu"'
)
...
...
@@ -178,14 +177,14 @@ class ExtEntitiesImporterTC(CubicWebTC):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
importer
=
self
.
importer
(
cnx
)
# First import
richelieu
=
ExtEntity
(
"Personne"
,
11
,
{
"nom"
:
set
([
"Richelieu Diacre"
])
})
richelieu
=
ExtEntity
(
"Personne"
,
11
,
{
"nom"
:
{
"Richelieu Diacre"
}
})
importer
.
import_entities
([
richelieu
])
cnx
.
commit
()
rset
=
cnx
.
execute
(
"Any X WHERE X is Personne"
)
entity
=
rset
.
get_entity
(
0
,
0
)
self
.
assertEqual
(
entity
.
nom
,
"Richelieu Diacre"
)
# Second import
richelieu
=
ExtEntity
(
"Personne"
,
11
,
{
"nom"
:
set
([
"Richelieu Cardinal"
])
})
richelieu
=
ExtEntity
(
"Personne"
,
11
,
{
"nom"
:
{
"Richelieu Cardinal"
}
})
importer
.
import_entities
([
richelieu
])
cnx
.
commit
()
rset
=
cnx
.
execute
(
"Any X WHERE X is Personne"
)
...
...
@@ -197,13 +196,13 @@ class ExtEntitiesImporterTC(CubicWebTC):
class
UseExtidAsCwuriTC
(
TestCase
):
def
test
(
self
):
personne
=
ExtEntity
(
"Personne"
,
b
"1"
,
{
"nom"
:
set
([
"de la lune"
])
,
"prenom"
:
set
([
"Jean"
])
}
"Personne"
,
b
"1"
,
{
"nom"
:
{
"de la lune"
}
,
"prenom"
:
{
"Jean"
}
}
)
mapping
=
{}
set_cwuri
=
use_extid_as_cwuri
(
mapping
)
list
(
set_cwuri
((
personne
,)))
self
.
assertIn
(
"cwuri"
,
personne
.
values
)
self
.
assertEqual
(
personne
.
values
[
"cwuri"
],
set
([
"1"
])
)
self
.
assertEqual
(
personne
.
values
[
"cwuri"
],
{
"1"
}
)
mapping
[
b
"1"
]
=
"whatever"
personne
.
values
.
pop
(
"cwuri"
)
list
(
set_cwuri
((
personne
,)))
...
...
@@ -213,7 +212,7 @@ class UseExtidAsCwuriTC(TestCase):
set_cwuri
=
use_extid_as_cwuri
(
mapping
)
list
(
set_cwuri
((
personne
,)))
self
.
assertIn
(
"cwuri"
,
personne
.
values
)
self
.
assertEqual
(
personne
.
values
[
"cwuri"
],
set
([
"ééé"
])
)
self
.
assertEqual
(
personne
.
values
[
"cwuri"
],
{
"ééé"
}
)
class
DropExtraValuesTC
(
CubicWebTC
):
...
...
@@ -222,8 +221,8 @@ class DropExtraValuesTC(CubicWebTC):
"Personne"
,
b
"1"
,
{
"nom"
:
set
([
"de la lune"
,
"di la luna"
])
,
"prenom"
:
set
([
"Jean"
])
,
"nom"
:
{
"de la lune"
,
"di la luna"
}
,
"prenom"
:
{
"Jean"
}
,
"enfant"
:
set
(
"23"
),
"connait"
:
set
(
"45"
),
},
...
...
@@ -241,7 +240,7 @@ def extentities_from_csv(fpath):
with
open
(
fpath
,
"rb"
)
as
f
:
for
uri
,
name
,
knows
in
ucsvreader
(
f
,
skipfirst
=
True
,
skip_empty
=
False
):
yield
ExtEntity
(
"Personne"
,
uri
,
{
"nom"
:
set
([
name
])
,
"connait"
:
set
([
knows
])
}
"Personne"
,
uri
,
{
"nom"
:
{
name
}
,
"connait"
:
{
knows
}
}
)
...
...
cubicweb/debug.py
View file @
c5ad4e65
...
...
@@ -56,7 +56,7 @@ def unsubscribe_to_debug_channel(channel, subscriber):
if
subscriber
not
in
SUBSCRIBERS
[
channel
]:
raise
Exception
(
"subscriber '
%s
' is not in debug channel '
%s'"
%
(
subscriber
,
channel
)
f
"subscriber '
{
subscriber
}
' is not in debug channel '
{
channel
}
'"
)
SUBSCRIBERS
[
channel
].
remove
(
subscriber
)
...
...
cubicweb/devtools/cwtwill.py
View file @
c5ad4e65
...
...
@@ -45,7 +45,7 @@ def has_link(text, url=""):
if
url
and
linkurl
!=
url
:
continue
return
raise
AssertionError
(
"link
%s (%s) not found"
%
(
text
,
url
)
)
raise
AssertionError
(
f
"link
{
text
}
(
{
url
}
) not found"
)
def
view
(
rql
,
vid
=
""
):
...
...
@@ -55,7 +55,7 @@ def view(rql, vid=""):
apply <vid> to <rql>'s rset
"""
if
vid
:
twc
.
go
(
"view?rql=
%s
&vid=
%s"
%
(
quote
(
rql
),
vid
))
twc
.
go
(
"view?rql=
{}
&vid=
{}"
.
format
(
quote
(
rql
),
vid
))
else
:
twc
.
go
(
"view?rql=%s"
%
quote
(
rql
))
...
...
@@ -99,7 +99,7 @@ def setvalue(formname, fieldname, value):
else
:
raise
ValueError
(
"could not find form named <%s>"
%
formname
)
eid
=
browser
.
get_form_field
(
form
,
"eid"
).
value
twc
.
formvalue
(
formname
,
"%s:%s"
%
(
fieldname
,
eid
)
,
value
)
twc
.
formvalue
(
formname
,
f
"
{
fieldname
}
:
{
eid
}
"
,
value
)
def
submitform
(
formname
,
submit_button
=
None
):
...
...
cubicweb/devtools/devctl.py
View file @
c5ad4e65
...
...
@@ -553,8 +553,8 @@ class I18nCubeMessageExtractor(object):
potfiles
.
append
(
self
.
schemapot
())
# messages from sourcecode
for
fmt
in
self
.
formats
:
collector
=
getattr
(
self
,
"collect_{
0
}"
.
format
(
fmt
))
extractor
=
getattr
(
self
,
"extract_{
0
}"
.
format
(
fmt
))
collector
=
getattr
(
self
,
"collect_{}"
.
format
(
fmt
))
extractor
=
getattr
(
self
,
"extract_{}"
.
format
(
fmt
))
files
=
collector
()
if
files
:
potfile
=
extractor
(
files
)
...
...
cubicweb/devtools/fake.py
View file @
c5ad4e65
...
...
@@ -72,7 +72,7 @@ class FakeRequest(ConnectionCubicWebRequestBase):
self
.
_url
=
kwargs
.
pop
(
"url"
,
None
)
if
self
.
_url
is
None
:
self
.
_url
=
"view?rql=Blop&vid=blop"
super
(
FakeRequest
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_session_data
=
{}
self
.
_request
=
DummyRequest
()
self
.
_csrf_storage
=
LegacySessionCSRFStoragePolicy
()
...
...
@@ -83,7 +83,7 @@ class FakeRequest(ConnectionCubicWebRequestBase):
def
set_cookie
(
self
,
name
,
value
,
maxage
=
300
,
expires
=
None
,
secure
=
False
,
httponly
=
False
):
super
(
FakeRequest
,
self
).
set_cookie
(
super
().
set_cookie
(
name
,
value
,
maxage
,
expires
,
secure
,
httponly
)
cookie
=
self
.
get_response_header
(
"Set-Cookie"
)
...
...
@@ -132,11 +132,11 @@ class FakeRequest(ConnectionCubicWebRequestBase):
values
=
(
values
,)
for
value
in
values
:
assert
value
is
not
None
args
.
append
(
"
%s=%s"
%
(
param
,
self
.
url_quote
(
value
)))
args
.
append
(
"
{}={}"
.
format
(
param
,
self
.
url_quote
(
value
)))
return
"&"
.
join
(
args
)
class
FakeUser
(
object
)
:
class
FakeUser
:
login
=
"toto"
eid
=
0