Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
0a437254
Commit
0a437254
authored
Jul 31, 2009
by
Olivier Aubert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python-ctypes: allow to specify class docstrings in override.py
parent
96cf477d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
34 deletions
+73
-34
bindings/python-ctypes/generate.py
bindings/python-ctypes/generate.py
+20
-8
bindings/python-ctypes/override.py
bindings/python-ctypes/override.py
+53
-26
No files found.
bindings/python-ctypes/generate.py
View file @
0a437254
...
@@ -418,8 +418,11 @@ def parse_override(name):
...
@@ -418,8 +418,11 @@ def parse_override(name):
"""Parse override definitions file.
"""Parse override definitions file.
It is possible to override methods definitions in classes.
It is possible to override methods definitions in classes.
It returns a tuple
(code, overriden_methods, docstring)
"""
"""
res
={}
code
={}
data=[]
data=[]
current=None
current=None
...
@@ -429,18 +432,24 @@ def parse_override(name):
...
@@ -429,18 +432,24 @@ def parse_override(name):
if m:
if m:
# Dump old data
# Dump old data
if current is not None:
if current is not None:
res
[current]="".join(data)
code
[current]="".join(data)
current=m.group(1)
current=m.group(1)
data=[]
data=[]
continue
continue
data.append(l)
data.append(l)
res
[current]="".join(data)
code
[current]="".join(data)
f.close()
f.close()
docstring={}
for k, v in code.iteritems():
if v.lstrip().startswith('"""'):
# Starting comment. Use it as docstring.
dummy, docstring[k], code[k]=v.split('"""', 2)
# Not robust wrt. internal methods, but this works for the moment.
# Not robust wrt. internal methods, but this works for the moment.
overrid
en_methods=dict( (k, re.findall('
^
\
s
+
def
\
s
+
(
\
w
+
)
', v)) for (k, v) in res
.iteritems() )
overrid
den_methods=dict( (k, re.findall('
^
\
s
+
def
\
s
+
(
\
w
+
)
', v, re.MULTILINE)) for (k, v) in code
.iteritems() )
return
res, overriden_methods
return
code, overridden_methods, docstring
def fix_python_comment(c):
def fix_python_comment(c):
"""Fix comment by removing first and last parameters (self and exception)
"""Fix comment by removing first and last parameters (self and exception)
...
@@ -470,11 +479,14 @@ def generate_wrappers(methods):
...
@@ -470,11 +479,14 @@ def generate_wrappers(methods):
),
),
key=operator.itemgetter(0))
key=operator.itemgetter(0))
overrides, overriden_methods=parse_override('
override
.
py
')
overrides, overriden_methods
, docstring
=parse_override('
override
.
py
')
for classname, el in itertools.groupby(elements, key=operator.itemgetter(0)):
for classname, el in itertools.groupby(elements, key=operator.itemgetter(0)):
print """class %(name)s(object):""" % {'
name
': classname}
if classname in docstring:
print '
"""%s
\
n
"""' % docstring[classname]
print """
print """
class %(name)s(object):
def __new__(cls, pointer=None):
def __new__(cls, pointer=None):
'''Internal method used for instanciating wrappers from ctypes.
'''Internal method used for instanciating wrappers from ctypes.
'''
'''
...
...
bindings/python-ctypes/override.py
View file @
0a437254
class
Instance
:
class
Instance
:
@
staticmethod
"""Create a new Instance instance.
def
new
(
*
p
):
"""Create a new Instance.
"""
e
=
VLCException
()
return
libvlc_new
(
len
(
p
),
p
,
e
)
class
MediaControl
:
It may take as parameter either:
@
staticmethod
* a string
def
new
(
*
p
):
* a list of strings as first parameters
"""Create a new MediaControl
* the parameters given as the constructor parameters (must be strings)
"""
* a MediaControl instance
e
=
MediaControlException
()
"""
return
mediacontrol_new
(
len
(
p
),
p
,
e
)
def
__new__
(
cls
,
*
p
):
if
p
and
p
[
0
]
==
0
:
return
None
elif
p
and
isinstance
(
p
[
0
],
(
int
,
long
)):
# instance creation from ctypes
o
=
object
.
__new__
(
cls
)
o
.
_as_parameter_
=
ctypes
.
c_void_p
(
p
[
0
])
return
o
elif
len
(
p
)
==
1
and
isinstance
(
p
[
0
],
basestring
):
# Only 1 string parameter: should be a parameter line
p
=
p
[
0
].
split
()
elif
len
(
p
)
==
1
and
isinstance
(
p
[
0
],
(
tuple
,
list
)):
p
=
p
[
0
]
if
p
and
isinstance
(
p
[
0
],
MediaControl
):
return
p
[
0
].
get_instance
()
else
:
e
=
VLCException
()
return
libvlc_new
(
len
(
p
),
p
,
e
)
@
staticmethod
class
MediaControl
:
def
new_from_instance
(
i
):
"""Create a new MediaControl instance
"""Create a new MediaControl from an existing Instance.
"""
e
=
MediaControlException
()
return
mediacontrol_new_from_instance
(
i
,
e
)
class
MediaList
:
It may take as parameter either:
def
__len__
(
self
):
* a string
e
=
VLCException
()
* a list of strings as first parameters
return
libvlc_media_list_count
(
self
,
e
)
* the parameters given as the constructor parameters (must be strings)
* a vlc.Instance
"""
def
__new__
(
cls
,
*
p
):
if
p
and
p
[
0
]
==
0
:
return
None
elif
p
and
isinstance
(
p
[
0
],
(
int
,
long
)):
# instance creation from ctypes
o
=
object
.
__new__
(
cls
)
o
.
_as_parameter_
=
ctypes
.
c_void_p
(
p
[
0
])
return
o
elif
len
(
p
)
==
1
and
isinstance
(
p
[
0
],
basestring
):
# Only 1 string parameter: should be a parameter line
p
=
p
[
0
].
split
()
elif
len
(
p
)
==
1
and
isinstance
(
p
[
0
],
(
tuple
,
list
)):
p
=
p
[
0
]
def
__getitem__
(
self
,
i
):
if
p
and
isinstance
(
p
[
0
],
Instance
):
e
=
VLCException
()
e
=
MediaControlException
()
return
libvlc_media_list_item_at_index
(
self
,
i
,
e
)
return
mediacontrol_new_from_instance
(
p
[
0
])
else
:
e
=
MediaControlException
()
return
mediacontrol_new
(
len
(
p
),
p
,
e
)
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