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):
"""Parse override definitions file.
It is possible to override methods definitions in classes.
It returns a tuple
(code, overriden_methods, docstring)
"""
res
={}
code
={}
data=[]
current=None
...
...
@@ -429,18 +432,24 @@ def parse_override(name):
if m:
# Dump old data
if current is not None:
res
[current]="".join(data)
code
[current]="".join(data)
current=m.group(1)
data=[]
continue
data.append(l)
res
[current]="".join(data)
code
[current]="".join(data)
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.
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):
"""Fix comment by removing first and last parameters (self and exception)
...
...
@@ -470,11 +479,14 @@ def generate_wrappers(methods):
),
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)):
print """class %(name)s(object):""" % {'
name
': classname}
if classname in docstring:
print '
"""%s
\
n
"""' % docstring[classname]
print """
class %(name)s(object):
def __new__(cls, pointer=None):
'''Internal method used for instanciating wrappers from ctypes.
'''
...
...
bindings/python-ctypes/override.py
View file @
0a437254
class
Instance
:
@
staticmethod
def
new
(
*
p
):
"""Create a new Instance.
"""
e
=
VLCException
()
return
libvlc_new
(
len
(
p
),
p
,
e
)
"""Create a new Instance instance.
class
MediaControl
:
@
staticmethod
def
new
(
*
p
):
"""Create a new MediaControl
"""
e
=
MediaControlException
()
return
mediacontrol_new
(
len
(
p
),
p
,
e
)
It may take as parameter either:
* a string
* a list of strings as first parameters
* the parameters given as the constructor parameters (must be strings)
* a MediaControl 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
]
if
p
and
isinstance
(
p
[
0
],
MediaControl
):
return
p
[
0
].
get_instance
()
else
:
e
=
VLCException
()
return
libvlc_new
(
len
(
p
),
p
,
e
)
@
staticmethod
def
new_from_instance
(
i
):
"""Create a new MediaControl from an existing Instance.
"""
e
=
MediaControlException
()
return
mediacontrol_new_from_instance
(
i
,
e
)
class
MediaControl
:
"""Create a new MediaControl instance
class
MediaList
:
def
__len__
(
self
):
e
=
VLCException
()
return
libvlc_media_list_count
(
self
,
e
)
It may take as parameter either:
* a string
* a list of strings as first parameters
* 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
):
e
=
VLCException
()
return
libvlc_media_list_item_at_index
(
self
,
i
,
e
)
if
p
and
isinstance
(
p
[
0
],
Instance
):
e
=
MediaControlException
()
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