Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DD4hep
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cepc
externals
mirroring
DD4hep
Commits
3c61526c
Commit
3c61526c
authored
5 years ago
by
Andre Sailer
Committed by
Marko Petric
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
DDG4: systematically cast to non-unicode str (for python2)
parent
f232e4e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DDG4/python/DDG4.py
+27
-10
27 additions, 10 deletions
DDG4/python/DDG4.py
with
27 additions
and
10 deletions
DDG4/python/DDG4.py
+
27
−
10
View file @
3c61526c
...
...
@@ -294,20 +294,37 @@ def _get(self, name):
raise
KeyError
(
msg
)
def
_set
(
self
,
name
,
value
):
a
=
Interface
.
toAction
(
self
)
if
isinstance
(
value
,
list
):
value
=
[
str
(
x
)
for
x
in
value
]
if
isinstance
(
value
,
dict
):
def
_deUnicode
(
value
):
"""
Turn any unicode literal into str, needed when passing to c++.
Recursively transverses dicts, lists, sets, tuples
:return: always a str
"""
if
isinstance
(
value
,
(
bool
,
float
,
six
.
integer_types
)):
value
=
value
elif
isinstance
(
value
,
six
.
string_types
):
value
=
str
(
value
)
elif
isinstance
(
value
,
(
list
,
set
,
tuple
)):
value
=
[
_deUnicode
(
x
)
for
x
in
value
]
elif
isinstance
(
value
,
dict
):
tempDict
=
{}
for
key
,
val
in
value
.
items
():
if
isinstance
(
val
,
six
.
string_types
):
val
=
str
(
val
)
tempDict
[
str
(
key
)
]
=
val
key
=
_deUnicode
(
key
)
val
=
_deUnicode
(
val
)
tempDict
[
key
]
=
val
value
=
tempDict
if
Interface
.
setProperty
(
a
,
str
(
name
),
str
(
value
)):
return
str
(
value
)
def
_set
(
self
,
name
,
value
):
"""
This function is called when properties are passed to the c++ objects.
"""
a
=
Interface
.
toAction
(
self
)
name
=
_deUnicode
(
name
)
value
=
_deUnicode
(
value
)
if
Interface
.
setProperty
(
a
,
name
,
value
):
return
msg
=
'
Geant4Action::SetProperty [Unhandled]: Cannot set
'
+
a
.
name
()
+
'
.
'
+
name
+
'
=
'
+
str
(
value
)
msg
=
'
Geant4Action::SetProperty [Unhandled]: Cannot set
'
+
a
.
name
()
+
'
.
'
+
name
+
'
=
'
+
value
raise
KeyError
(
msg
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment