Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
e055b68c
Commit
e055b68c
authored
Mar 28, 2014
by
Roman Donchenko
Committed by
OpenCV Buildbot
Mar 28, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2403 from hbristow:issue-3451
parents
0b4534d4
61c22d58
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
51 deletions
+54
-51
__init__.py
3rdparty/jinja2/markupsafe/__init__.py
+2
-2
_native.py
3rdparty/jinja2/markupsafe/_native.py
+1
-1
utils.py
3rdparty/jinja2/utils.py
+1
-1
rst_parser.py
modules/java/generator/rst_parser.py
+0
-0
build_info.py
modules/matlab/generator/build_info.py
+1
-1
cvmex.py
modules/matlab/generator/cvmex.py
+1
-1
filters.py
modules/matlab/generator/filters.py
+1
-2
gen_matlab.py
modules/matlab/generator/gen_matlab.py
+19
-18
parse_tree.py
modules/matlab/generator/parse_tree.py
+28
-25
No files found.
3rdparty/jinja2/markupsafe/__init__.py
View file @
e055b68c
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
:license: BSD, see LICENSE for more details.
:license: BSD, see LICENSE for more details.
"""
"""
import
re
import
re
from
_compat
import
text_type
,
string_types
,
int_types
,
\
from
.
_compat
import
text_type
,
string_types
,
int_types
,
\
unichr
,
PY2
unichr
,
PY2
...
@@ -227,7 +227,7 @@ class _MarkupEscapeHelper(object):
...
@@ -227,7 +227,7 @@ class _MarkupEscapeHelper(object):
try
:
try
:
from
_speedups
import
escape
,
escape_silent
,
soft_unicode
from
_speedups
import
escape
,
escape_silent
,
soft_unicode
except
ImportError
:
except
ImportError
:
from
_native
import
escape
,
escape_silent
,
soft_unicode
from
.
_native
import
escape
,
escape_silent
,
soft_unicode
if
not
PY2
:
if
not
PY2
:
soft_str
=
soft_unicode
soft_str
=
soft_unicode
...
...
3rdparty/jinja2/markupsafe/_native.py
View file @
e055b68c
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
:copyright: (c) 2010 by Armin Ronacher.
:copyright: (c) 2010 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
:license: BSD, see LICENSE for more details.
"""
"""
from
_compat
import
text_type
from
.
_compat
import
text_type
def
escape
(
s
):
def
escape
(
s
):
...
...
3rdparty/jinja2/utils.py
View file @
e055b68c
...
@@ -517,4 +517,4 @@ class Joiner(object):
...
@@ -517,4 +517,4 @@ class Joiner(object):
# Imported here because that's where it was in the past
# Imported here because that's where it was in the past
from
markupsafe
import
Markup
,
escape
,
soft_unicode
from
.
markupsafe
import
Markup
,
escape
,
soft_unicode
modules/java/generator/rst_parser.py
View file @
e055b68c
This diff is collapsed.
Click to expand it.
modules/matlab/generator/build_info.py
View file @
e055b68c
...
@@ -21,7 +21,7 @@ def substitute(build, output_dir):
...
@@ -21,7 +21,7 @@ def substitute(build, output_dir):
# populate template
# populate template
populated
=
template
.
render
(
build
=
build
,
time
=
time
)
populated
=
template
.
render
(
build
=
build
,
time
=
time
)
with
open
(
os
.
path
.
join
(
output_dir
,
'buildInformation.m'
),
'wb'
)
as
f
:
with
open
(
os
.
path
.
join
(
output_dir
,
'buildInformation.m'
),
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
"""
"""
...
...
modules/matlab/generator/cvmex.py
View file @
e055b68c
...
@@ -22,7 +22,7 @@ def substitute(cv, output_dir):
...
@@ -22,7 +22,7 @@ def substitute(cv, output_dir):
# populate template
# populate template
populated
=
template
.
render
(
cv
=
cv
,
time
=
time
)
populated
=
template
.
render
(
cv
=
cv
,
time
=
time
)
with
open
(
os
.
path
.
join
(
output_dir
,
'mex.m'
),
'wb'
)
as
f
:
with
open
(
os
.
path
.
join
(
output_dir
,
'mex.m'
),
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
"""
"""
...
...
modules/matlab/generator/filters.py
View file @
e055b68c
from
textwrap
import
TextWrapper
from
textwrap
import
TextWrapper
from
string
import
split
,
join
import
re
,
os
import
re
,
os
# precompile a URL matching regular expression
# precompile a URL matching regular expression
urlexpr
=
re
.
compile
(
r"((https?):((//)|(\\\\))+[\w\d:#@
%
/;$()~_?\+-=\\\.&]*)"
,
re
.
MULTILINE
|
re
.
UNICODE
)
urlexpr
=
re
.
compile
(
r"((https?):((//)|(\\\\))+[\w\d:#@
%
/;$()~_?\+-=\\\.&]*)"
,
re
.
MULTILINE
|
re
.
UNICODE
)
...
@@ -177,4 +176,4 @@ def comment(text, wrap=80, escape='% ', escape_first='', escape_last=''):
...
@@ -177,4 +176,4 @@ def comment(text, wrap=80, escape='% ', escape_first='', escape_last=''):
escapn
=
'
\n
'
+
escape
escapn
=
'
\n
'
+
escape
lines
=
text
.
split
(
'
\n
'
)
lines
=
text
.
split
(
'
\n
'
)
wlines
=
(
tw
.
wrap
(
line
)
for
line
in
lines
)
wlines
=
(
tw
.
wrap
(
line
)
for
line
in
lines
)
return
escape_first
+
escape
+
join
((
join
(
line
,
escapn
)
for
line
in
wlines
),
escapn
)
+
escape_last
return
escape_first
+
escape
+
escapn
.
join
(
escapn
.
join
(
line
)
for
line
in
wlines
)
+
escape_last
modules/matlab/generator/gen_matlab.py
View file @
e055b68c
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
,
re
,
os
,
time
from
string
import
Template
from
parse_tree
import
ParseTree
,
todict
,
constants
from
filters
import
*
class
MatlabWrapperGenerator
(
object
):
class
MatlabWrapperGenerator
(
object
):
"""
"""
...
@@ -22,9 +26,14 @@ class MatlabWrapperGenerator(object):
...
@@ -22,9 +26,14 @@ class MatlabWrapperGenerator(object):
The output_dir specifies the directory to write the generated sources
The output_dir specifies the directory to write the generated sources
to.
to.
"""
"""
# dynamically import the parsers
from
jinja2
import
Environment
,
FileSystemLoader
import
hdr_parser
import
rst_parser
# parse each of the files and store in a dictionary
# parse each of the files and store in a dictionary
# as a separate "namespace"
# as a separate "namespace"
parser
=
CppHeaderParser
()
parser
=
hdr_parser
.
CppHeaderParser
()
rst
=
rst_parser
.
RstParser
(
parser
)
rst
=
rst_parser
.
RstParser
(
parser
)
rst_parser
.
verbose
=
False
rst_parser
.
verbose
=
False
rst_parser
.
show_warnings
=
False
rst_parser
.
show_warnings
=
False
...
@@ -91,13 +100,13 @@ class MatlabWrapperGenerator(object):
...
@@ -91,13 +100,13 @@ class MatlabWrapperGenerator(object):
output_class_dir
=
output_dir
+
'/+cv'
output_class_dir
=
output_dir
+
'/+cv'
output_map_dir
=
output_dir
+
'/map'
output_map_dir
=
output_dir
+
'/map'
if
not
os
.
path
.
isdir
(
output_source_dir
):
if
not
os
.
path
.
isdir
(
output_source_dir
):
os
.
m
kdir
(
output_source_dir
)
os
.
m
akedirs
(
output_source_dir
)
if
not
os
.
path
.
isdir
(
output_private_dir
):
if
not
os
.
path
.
isdir
(
output_private_dir
):
os
.
m
kdir
(
output_private_dir
)
os
.
m
akedirs
(
output_private_dir
)
if
not
os
.
path
.
isdir
(
output_class_dir
):
if
not
os
.
path
.
isdir
(
output_class_dir
):
os
.
m
kdir
(
output_class_dir
)
os
.
m
akedirs
(
output_class_dir
)
if
not
os
.
path
.
isdir
(
output_map_dir
):
if
not
os
.
path
.
isdir
(
output_map_dir
):
os
.
m
kdir
(
output_map_dir
)
os
.
m
akedirs
(
output_map_dir
)
# populate templates
# populate templates
for
namespace
in
parse_tree
.
namespaces
:
for
namespace
in
parse_tree
.
namespaces
:
...
@@ -105,27 +114,27 @@ class MatlabWrapperGenerator(object):
...
@@ -105,27 +114,27 @@ class MatlabWrapperGenerator(object):
for
method
in
namespace
.
methods
:
for
method
in
namespace
.
methods
:
populated
=
tfunction
.
render
(
fun
=
method
,
time
=
time
,
includes
=
namespace
.
name
)
populated
=
tfunction
.
render
(
fun
=
method
,
time
=
time
,
includes
=
namespace
.
name
)
with
open
(
output_source_dir
+
'/'
+
method
.
name
+
'.cpp'
,
'wb'
)
as
f
:
with
open
(
output_source_dir
+
'/'
+
method
.
name
+
'.cpp'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
if
namespace
.
name
in
doc
and
method
.
name
in
doc
[
namespace
.
name
]:
if
namespace
.
name
in
doc
and
method
.
name
in
doc
[
namespace
.
name
]:
populated
=
tdoc
.
render
(
fun
=
method
,
doc
=
doc
[
namespace
.
name
][
method
.
name
],
time
=
time
)
populated
=
tdoc
.
render
(
fun
=
method
,
doc
=
doc
[
namespace
.
name
][
method
.
name
],
time
=
time
)
with
open
(
output_class_dir
+
'/'
+
method
.
name
+
'.m'
,
'wb'
)
as
f
:
with
open
(
output_class_dir
+
'/'
+
method
.
name
+
'.m'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
# classes
# classes
for
clss
in
namespace
.
classes
:
for
clss
in
namespace
.
classes
:
# cpp converter
# cpp converter
populated
=
tclassc
.
render
(
clss
=
clss
,
time
=
time
)
populated
=
tclassc
.
render
(
clss
=
clss
,
time
=
time
)
with
open
(
output_private_dir
+
'/'
+
clss
.
name
+
'Bridge.cpp'
,
'wb'
)
as
f
:
with
open
(
output_private_dir
+
'/'
+
clss
.
name
+
'Bridge.cpp'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
# matlab classdef
# matlab classdef
populated
=
tclassm
.
render
(
clss
=
clss
,
time
=
time
)
populated
=
tclassm
.
render
(
clss
=
clss
,
time
=
time
)
with
open
(
output_class_dir
+
'/'
+
clss
.
name
+
'.m'
,
'wb'
)
as
f
:
with
open
(
output_class_dir
+
'/'
+
clss
.
name
+
'.m'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
# create a global constants lookup table
# create a global constants lookup table
const
=
dict
(
constants
(
todict
(
parse_tree
.
namespaces
)))
const
=
dict
(
constants
(
todict
(
parse_tree
.
namespaces
)))
populated
=
tconst
.
render
(
constants
=
const
,
time
=
time
)
populated
=
tconst
.
render
(
constants
=
const
,
time
=
time
)
with
open
(
output_dir
+
'/cv.m'
,
'wb'
)
as
f
:
with
open
(
output_dir
+
'/cv.m'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
f
.
write
(
populated
.
encode
(
'utf-8'
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
@@ -168,7 +177,6 @@ if __name__ == "__main__":
...
@@ -168,7 +177,6 @@ if __name__ == "__main__":
"""
"""
# parse the input options
# parse the input options
import
sys
,
re
,
os
,
time
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
parser
=
ArgumentParser
()
parser
=
ArgumentParser
()
parser
.
add_argument
(
'--jinja2'
)
parser
.
add_argument
(
'--jinja2'
)
...
@@ -185,13 +193,6 @@ if __name__ == "__main__":
...
@@ -185,13 +193,6 @@ if __name__ == "__main__":
sys
.
path
.
append
(
args
.
hdrparser
)
sys
.
path
.
append
(
args
.
hdrparser
)
sys
.
path
.
append
(
args
.
rstparser
)
sys
.
path
.
append
(
args
.
rstparser
)
from
string
import
Template
from
hdr_parser
import
CppHeaderParser
import
rst_parser
from
parse_tree
import
ParseTree
,
todict
,
constants
from
filters
import
*
from
jinja2
import
Environment
,
FileSystemLoader
# create the generator
# create the generator
mwg
=
MatlabWrapperGenerator
()
mwg
=
MatlabWrapperGenerator
()
mwg
.
gen
(
args
.
moduleroot
,
args
.
modules
,
args
.
extra
,
args
.
outdir
)
mwg
.
gen
(
args
.
moduleroot
,
args
.
modules
,
args
.
extra
,
args
.
outdir
)
modules/matlab/generator/parse_tree.py
View file @
e055b68c
from
string
import
join
import
collections
from
textwrap
import
fill
from
textwrap
import
fill
from
filters
import
*
from
filters
import
*
try
:
# Python 2.7+
basestring
except
NameError
:
# Python 3.3+
basestring
=
str
class
ParseTree
(
object
):
class
ParseTree
(
object
):
"""
"""
...
@@ -74,7 +80,7 @@ class ParseTree(object):
...
@@ -74,7 +80,7 @@ class ParseTree(object):
self
.
namespaces
=
namespaces
if
namespaces
else
[]
self
.
namespaces
=
namespaces
if
namespaces
else
[]
def
__str__
(
self
):
def
__str__
(
self
):
return
join
((
ns
.
__str__
()
for
ns
in
self
.
namespaces
),
'
\n\n\n
'
)
return
'
\n\n\n
'
.
join
(
ns
.
__str__
()
for
ns
in
self
.
namespaces
)
def
build
(
self
,
namespaces
):
def
build
(
self
,
namespaces
):
babel
=
Translator
()
babel
=
Translator
()
...
@@ -94,7 +100,7 @@ class ParseTree(object):
...
@@ -94,7 +100,7 @@ class ParseTree(object):
constants
.
append
(
obj
)
constants
.
append
(
obj
)
else
:
else
:
raise
TypeError
(
'Unexpected object type: '
+
str
(
type
(
obj
)))
raise
TypeError
(
'Unexpected object type: '
+
str
(
type
(
obj
)))
self
.
namespaces
.
append
(
Namespace
(
name
,
constants
,
class_tree
.
values
(
),
methods
))
self
.
namespaces
.
append
(
Namespace
(
name
,
constants
,
list
(
class_tree
.
values
()
),
methods
))
def
insertIntoClassTree
(
self
,
obj
,
class_tree
):
def
insertIntoClassTree
(
self
,
obj
,
class_tree
):
cname
=
obj
.
name
if
type
(
obj
)
is
Class
else
obj
.
clss
cname
=
obj
.
name
if
type
(
obj
)
is
Class
else
obj
.
clss
...
@@ -208,9 +214,9 @@ class Namespace(object):
...
@@ -208,9 +214,9 @@ class Namespace(object):
def
__str__
(
self
):
def
__str__
(
self
):
return
'namespace '
+
self
.
name
+
' {
\n\n
'
+
\
return
'namespace '
+
self
.
name
+
' {
\n\n
'
+
\
(
join
((
c
.
__str__
()
for
c
in
self
.
constants
),
'
\n
'
)
+
'
\n\n
'
if
self
.
constants
else
''
)
+
\
(
'
\n
'
.
join
(
c
.
__str__
()
for
c
in
self
.
constants
)
+
'
\n\n
'
if
self
.
constants
else
''
)
+
\
(
join
((
f
.
__str__
()
for
f
in
self
.
methods
),
'
\n
'
)
+
'
\n\n
'
if
self
.
methods
else
''
)
+
\
(
'
\n
'
.
join
(
f
.
__str__
()
for
f
in
self
.
methods
)
+
'
\n\n
'
if
self
.
methods
else
''
)
+
\
(
join
((
o
.
__str__
()
for
o
in
self
.
classes
),
'
\n\n
'
)
if
self
.
classes
else
''
)
+
'
\n
};'
(
'
\n\n
'
.
join
(
o
.
__str__
()
for
o
in
self
.
classes
)
if
self
.
classes
else
''
)
+
'
\n
};'
class
Class
(
object
):
class
Class
(
object
):
"""
"""
...
@@ -228,8 +234,8 @@ class Class(object):
...
@@ -228,8 +234,8 @@ class Class(object):
def
__str__
(
self
):
def
__str__
(
self
):
return
'class '
+
self
.
name
+
' {
\n\t
'
+
\
return
'class '
+
self
.
name
+
' {
\n\t
'
+
\
(
join
((
c
.
__str__
()
for
c
in
self
.
constants
),
'
\n\t
'
)
+
'
\n\n\t
'
if
self
.
constants
else
''
)
+
\
(
'
\n\t
'
.
join
(
c
.
__str__
()
for
c
in
self
.
constants
)
+
'
\n\n\t
'
if
self
.
constants
else
''
)
+
\
(
join
((
f
.
__str__
()
for
f
in
self
.
methods
),
'
\n\t
'
)
if
self
.
methods
else
''
)
+
'
\n
};'
(
'
\n\t
'
.
join
(
f
.
__str__
()
for
f
in
self
.
methods
)
if
self
.
methods
else
''
)
+
'
\n
};'
class
Method
(
object
):
class
Method
(
object
):
"""
"""
...
@@ -260,7 +266,7 @@ class Method(object):
...
@@ -260,7 +266,7 @@ class Method(object):
def
__str__
(
self
):
def
__str__
(
self
):
return
(
self
.
rtp
+
' '
if
self
.
rtp
else
''
)
+
self
.
name
+
'('
+
\
return
(
self
.
rtp
+
' '
if
self
.
rtp
else
''
)
+
self
.
name
+
'('
+
\
join
((
arg
.
__str__
()
for
arg
in
self
.
req
+
self
.
opt
),
', '
)
+
\
', '
.
join
(
arg
.
__str__
()
for
arg
in
self
.
req
+
self
.
opt
)
+
\
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
class
Argument
(
object
):
class
Argument
(
object
):
...
@@ -334,23 +340,20 @@ def constants(tree):
...
@@ -334,23 +340,20 @@ def constants(tree):
for
gen
in
constants
(
val
):
for
gen
in
constants
(
val
):
yield
gen
yield
gen
def
todict
(
obj
,
classkey
=
None
):
def
todict
(
obj
):
"""
"""
Convert the ParseTree to a dictionary, stripping all objects of their
Recursively convert a Python object graph to sequences (lists)
methods and converting class names to strings
and mappings (dicts) of primitives (bool, int, float, string, ...)
"""
"""
if
isinstance
(
obj
,
dict
):
if
isinstance
(
obj
,
basestring
):
for
k
in
obj
.
keys
():
obj
[
k
]
=
todict
(
obj
[
k
],
classkey
)
return
obj
return
obj
elif
hasattr
(
obj
,
"__iter__"
):
elif
isinstance
(
obj
,
dict
):
return
[
todict
(
v
,
classkey
)
for
v
in
obj
]
return
dict
((
key
,
todict
(
val
))
for
key
,
val
in
obj
.
items
())
elif
hasattr
(
obj
,
"__dict__"
):
elif
isinstance
(
obj
,
collections
.
Iterable
):
data
=
dict
([(
key
,
todict
(
value
,
classkey
))
return
[
todict
(
val
)
for
val
in
obj
]
for
key
,
value
in
obj
.
__dict__
.
iteritems
()
elif
hasattr
(
obj
,
'__dict__'
):
if
not
callable
(
value
)
and
not
key
.
startswith
(
'_'
)])
return
todict
(
vars
(
obj
))
if
classkey
is
not
None
and
hasattr
(
obj
,
"__class__"
):
elif
hasattr
(
obj
,
'__slots__'
):
data
[
classkey
]
=
obj
.
__class__
.
__name__
return
todict
(
dict
((
name
,
getattr
(
obj
,
name
))
for
name
in
getattr
(
obj
,
'__slots__'
)))
return
data
else
:
return
obj
return
obj
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment