Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
4329f903
Commit
4329f903
authored
Jan 26, 2016
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
Use tuples for multiple attribute and array access
Removes string mangling
parent
dec03ceb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
utils/blend2json.py
+1
-1
1 addition, 1 deletion
utils/blend2json.py
utils/blendfile.py
+27
-14
27 additions, 14 deletions
utils/blendfile.py
with
28 additions
and
15 deletions
utils/blend2json.py
+
1
−
1
View file @
4329f903
...
@@ -168,7 +168,7 @@ def do_bblock_filter(filters, blend, block, meta_keyval, data_keyval):
...
@@ -168,7 +168,7 @@ def do_bblock_filter(filters, blend, block, meta_keyval, data_keyval):
if
fld
is
None
:
if
fld
is
None
:
continue
continue
if
fld
.
dna_name
.
is_pointer
:
if
fld
.
dna_name
.
is_pointer
:
paths
=
([
fld
.
dna_name
.
name_only
+
b
"
[
"
+
str
(
i
).
encode
()
+
b
"
]
"
for
i
in
range
(
fld
.
dna_name
.
array_size
)]
paths
=
([
(
fld
.
dna_name
.
name_only
,
i
)
for
i
in
range
(
fld
.
dna_name
.
array_size
)]
if
fld
.
dna_name
.
array_size
>
1
else
[
fld
.
dna_name
.
name_only
])
if
fld
.
dna_name
.
array_size
>
1
else
[
fld
.
dna_name
.
name_only
])
for
p
in
paths
:
for
p
in
paths
:
child_block
=
block
.
get_pointer
(
p
)
child_block
=
block
.
get_pointer
(
p
)
...
...
This diff is collapsed.
Click to expand it.
utils/blendfile.py
+
27
−
14
View file @
4329f903
...
@@ -416,7 +416,13 @@ class BlendFileBlock:
...
@@ -416,7 +416,13 @@ class BlendFileBlock:
use_nil
=
True
,
use_str
=
True
,
use_nil
=
True
,
use_str
=
True
,
base_index
=
0
,
base_index
=
0
,
):
):
path_full
=
path_root
+
b
"
.
"
+
path
if
path_root
else
path
if
path_root
:
path_full
=
(
(
path_root
if
type
(
path_root
)
is
tuple
else
(
path_root
,
))
+
(
path
if
type
(
path
)
is
tuple
else
(
path
,
)))
else
:
path_full
=
path
try
:
try
:
yield
(
path_full
,
self
.
get
(
path_full
,
default
,
sdna_index_refine
,
use_nil
,
use_str
,
base_index
))
yield
(
path_full
,
self
.
get
(
path_full
,
default
,
sdna_index_refine
,
use_nil
,
use_str
,
base_index
))
except
NotImplementedError
as
ex
:
except
NotImplementedError
as
ex
:
...
@@ -689,18 +695,27 @@ class DNAStruct:
...
@@ -689,18 +695,27 @@ class DNAStruct:
self
.
user_data
=
None
self
.
user_data
=
None
def
field_from_path
(
self
,
header
,
handle
,
path
):
def
field_from_path
(
self
,
header
,
handle
,
path
):
assert
(
type
(
path
)
==
bytes
)
"""
# support 'id.name'
Support lookups as bytes or a tuple of bytes and optional index.
name
,
_
,
name_tail
=
path
.
partition
(
b
'
.
'
)
C style
'
id.name
'
--> (b
'
id
'
, b
'
name
'
)
# support 'mtex[1].tex'
C style
'
array[4]
'
--> (
'
array
'
, 4)
# note, multi-dimensional arrays not supported
"""
# FIXME: 'mtex[1]' works, but not 'mtex[1].tex', why is this???
if
type
(
path
)
is
tuple
:
if
name
.
endswith
(
b
'
]
'
):
name
=
path
[
0
]
name
,
_
,
index
=
name
[:
-
1
].
partition
(
b
'
[
'
)
if
len
(
path
)
>=
2
and
type
(
path
[
1
])
is
not
bytes
:
index
=
int
(
index
)
name_tail
=
path
[
2
:]
index
=
path
[
1
]
assert
(
type
(
index
)
is
int
)
else
:
else
:
name_tail
=
path
[
1
:]
index
=
0
index
=
0
else
:
name
=
path
name_tail
=
None
index
=
0
assert
(
type
(
name
)
is
bytes
)
field
=
self
.
field_from_name
.
get
(
name
)
field
=
self
.
field_from_name
.
get
(
name
)
...
@@ -713,7 +728,7 @@ class DNAStruct:
...
@@ -713,7 +728,7 @@ class DNAStruct:
index_offset
=
field
.
dna_type
.
size
*
index
index_offset
=
field
.
dna_type
.
size
*
index
assert
(
index_offset
<
field
.
dna_size
)
assert
(
index_offset
<
field
.
dna_size
)
handle
.
seek
(
index_offset
,
os
.
SEEK_CUR
)
handle
.
seek
(
index_offset
,
os
.
SEEK_CUR
)
if
name_tail
==
b
''
:
if
not
name_tail
:
# None or ()
return
field
return
field
else
:
else
:
return
field
.
dna_type
.
field_from_path
(
header
,
handle
,
name_tail
)
return
field
.
dna_type
.
field_from_path
(
header
,
handle
,
name_tail
)
...
@@ -722,8 +737,6 @@ class DNAStruct:
...
@@ -722,8 +737,6 @@ class DNAStruct:
default
=
...,
default
=
...,
use_nil
=
True
,
use_str
=
True
,
use_nil
=
True
,
use_str
=
True
,
):
):
assert
(
type
(
path
)
==
bytes
)
field
=
self
.
field_from_path
(
header
,
handle
,
path
)
field
=
self
.
field_from_path
(
header
,
handle
,
path
)
if
field
is
None
:
if
field
is
None
:
if
default
is
not
...:
if
default
is
not
...:
...
...
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