Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
8f5d9212
Commit
8f5d9212
authored
Dec 03, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some pylinting
parent
4185016f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
44 deletions
+49
-44
vmodtool.py
lib/libvcc/vmodtool.py
+49
-44
No files found.
lib/libvcc/vmodtool.py
View file @
8f5d9212
...
@@ -120,12 +120,12 @@ CTYPES.update(PRIVS)
...
@@ -120,12 +120,12 @@ CTYPES.update(PRIVS)
#######################################################################
#######################################################################
def
is_quoted
(
str
):
def
is_quoted
(
txt
):
return
len
(
str
)
>
2
and
str
[
0
]
==
str
[
-
1
]
and
str
[
0
]
in
(
'"'
,
"'"
)
return
len
(
txt
)
>
2
and
txt
[
0
]
==
txt
[
-
1
]
and
txt
[
0
]
in
(
'"'
,
"'"
)
def
unquote
(
str
):
def
unquote
(
txt
):
assert
is_quoted
(
str
)
assert
is_quoted
(
txt
)
return
str
[
1
:
-
1
]
return
txt
[
1
:
-
1
]
#######################################################################
#######################################################################
...
@@ -364,17 +364,17 @@ class ProtoType(object):
...
@@ -364,17 +364,17 @@ class ProtoType(object):
self
.
args
.
append
(
t
)
self
.
args
.
append
(
t
)
def
vcl_proto
(
self
,
short
,
pfx
=
""
):
def
vcl_proto
(
self
,
short
,
pfx
=
""
):
if
type
(
self
.
st
)
==
s_method
:
if
isinstance
(
self
.
st
,
MethodStanza
)
:
pfx
+=
pfx
pfx
+=
pfx
s
=
pfx
s
=
pfx
if
type
(
self
.
st
)
==
s_object
:
if
isinstance
(
self
.
st
,
ObjectStanza
)
:
s
+=
"new "
+
self
.
obj
+
" = "
s
+=
"new "
+
self
.
obj
+
" = "
elif
self
.
retval
is
not
None
:
elif
self
.
retval
is
not
None
:
s
+=
self
.
retval
.
vcl
()
+
" "
s
+=
self
.
retval
.
vcl
()
+
" "
if
type
(
self
.
st
)
==
s_object
:
if
isinstance
(
self
.
st
,
ObjectStanza
)
:
s
+=
self
.
st
.
vcc
.
modname
+
"."
+
self
.
name
+
"("
s
+=
self
.
st
.
vcc
.
modname
+
"."
+
self
.
name
+
"("
elif
type
(
self
.
st
)
==
s_method
:
elif
isinstance
(
self
.
st
,
MethodStanza
)
:
s
+=
self
.
obj
+
self
.
bname
+
"("
s
+=
self
.
obj
+
self
.
bname
+
"("
else
:
else
:
s
+=
self
.
name
+
"("
s
+=
self
.
name
+
"("
...
@@ -414,7 +414,7 @@ class ProtoType(object):
...
@@ -414,7 +414,7 @@ class ProtoType(object):
write_rst_hdr
(
fo
,
s
,
'-'
)
write_rst_hdr
(
fo
,
s
,
'-'
)
fo
.
write
(
"
\n
::
\n\n
"
+
self
.
vcl_proto
(
False
,
pfx
=
" "
)
+
"
\n
"
)
fo
.
write
(
"
\n
::
\n\n
"
+
self
.
vcl_proto
(
False
,
pfx
=
" "
)
+
"
\n
"
)
def
synopsis
(
self
,
fo
,
man
):
def
synopsis
(
self
,
fo
,
unused_
man
):
fo
.
write
(
self
.
vcl_proto
(
True
,
pfx
=
" "
)
+
"
\n
"
)
fo
.
write
(
self
.
vcl_proto
(
True
,
pfx
=
" "
)
+
"
\n
"
)
fo
.
write
(
"
\n
"
)
fo
.
write
(
"
\n
"
)
...
@@ -489,7 +489,7 @@ class ProtoType(object):
...
@@ -489,7 +489,7 @@ class ProtoType(object):
#######################################################################
#######################################################################
class
s
tanza
(
object
):
class
S
tanza
(
object
):
def
__init__
(
self
,
toks
,
l0
,
doc
,
vcc
):
def
__init__
(
self
,
toks
,
l0
,
doc
,
vcc
):
self
.
toks
=
toks
self
.
toks
=
toks
self
.
line
=
l0
self
.
line
=
l0
...
@@ -504,6 +504,9 @@ class stanza(object):
...
@@ -504,6 +504,9 @@ class stanza(object):
self
.
proto
=
None
self
.
proto
=
None
self
.
parse
()
self
.
parse
()
def
parse
(
self
):
assert
"subclass should have defined"
==
"parse method"
def
dump
(
self
):
def
dump
(
self
):
print
(
type
(
self
),
self
.
line
)
print
(
type
(
self
),
self
.
line
)
...
@@ -524,34 +527,33 @@ class stanza(object):
...
@@ -524,34 +527,33 @@ class stanza(object):
self
.
rsttail
(
fo
,
man
)
self
.
rsttail
(
fo
,
man
)
fo
.
write
(
"
\n
"
)
fo
.
write
(
"
\n
"
)
def
rsthead
(
self
,
fo
,
man
):
def
rsthead
(
self
,
fo
,
unused_man
):
if
self
.
proto
is
None
:
if
self
.
proto
is
not
None
:
return
self
.
proto
.
rsthead
(
fo
)
self
.
proto
.
rsthead
(
fo
)
def
rstmid
(
self
,
fo
,
man
):
def
rstmid
(
self
,
fo
,
unused_
man
):
fo
.
write
(
"
\n
"
.
join
(
self
.
doc
)
+
"
\n
"
)
fo
.
write
(
"
\n
"
.
join
(
self
.
doc
)
+
"
\n
"
)
def
rsttail
(
self
,
fo
,
man
):
def
rsttail
(
self
,
unused_fo
,
unused_
man
):
return
return
def
synopsis
(
self
,
fo
,
man
):
def
synopsis
(
self
,
fo
,
man
):
if
self
.
proto
is
not
None
:
if
self
.
proto
is
not
None
:
self
.
proto
.
synopsis
(
fo
,
man
)
self
.
proto
.
synopsis
(
fo
,
man
)
def
cstuff
(
self
,
fo
,
where
):
def
cstuff
(
self
,
unused_fo
,
unused_
where
):
return
return
def
cstruct
(
self
,
fo
,
define
):
def
cstruct
(
self
,
unused_fo
,
unused_
define
):
return
return
def
json
(
self
,
jl
):
def
json
(
self
,
unused_
jl
):
return
return
#######################################################################
#######################################################################
class
s_module
(
s
tanza
):
class
ModuleStanza
(
S
tanza
):
''' $Module modname man_section description ... '''
''' $Module modname man_section description ... '''
...
@@ -617,7 +619,7 @@ class s_module(stanza):
...
@@ -617,7 +619,7 @@ class s_module(stanza):
fo
.
write
(
"
\n
"
)
fo
.
write
(
"
\n
"
)
class
s_abi
(
s
tanza
):
class
ABIStanza
(
S
tanza
):
''' $ABI [strict|vrt] '''
''' $ABI [strict|vrt] '''
...
@@ -635,7 +637,7 @@ class s_abi(stanza):
...
@@ -635,7 +637,7 @@ class s_abi(stanza):
self
.
vcc
.
contents
.
append
(
self
)
self
.
vcc
.
contents
.
append
(
self
)
class
s_prefix
(
s
tanza
):
class
PrefixStanza
(
S
tanza
):
''' $Prefix symbol '''
''' $Prefix symbol '''
...
@@ -646,7 +648,7 @@ class s_prefix(stanza):
...
@@ -646,7 +648,7 @@ class s_prefix(stanza):
self
.
vcc
.
contents
.
append
(
self
)
self
.
vcc
.
contents
.
append
(
self
)
class
s_synopsis
(
s
tanza
):
class
SynopsisStanza
(
S
tanza
):
''' $Synopsis [auto|manual] '''
''' $Synopsis [auto|manual] '''
...
@@ -664,7 +666,7 @@ class s_synopsis(stanza):
...
@@ -664,7 +666,7 @@ class s_synopsis(stanza):
self
.
vcc
.
contents
.
append
(
self
)
self
.
vcc
.
contents
.
append
(
self
)
class
s_event
(
s
tanza
):
class
EventStanza
(
S
tanza
):
''' $Event function_name '''
''' $Event function_name '''
...
@@ -696,7 +698,7 @@ class s_event(stanza):
...
@@ -696,7 +698,7 @@ class s_event(stanza):
])
])
class
s_function
(
s
tanza
):
class
FunctionStanza
(
S
tanza
):
def
parse
(
self
):
def
parse
(
self
):
self
.
proto
=
ProtoType
(
self
)
self
.
proto
=
ProtoType
(
self
)
self
.
rstlbl
=
"func_"
+
self
.
proto
.
name
self
.
rstlbl
=
"func_"
+
self
.
proto
.
name
...
@@ -716,7 +718,7 @@ class s_function(stanza):
...
@@ -716,7 +718,7 @@ class s_function(stanza):
self
.
proto
.
json
(
jl
[
-
1
],
self
.
proto
.
cname
())
self
.
proto
.
json
(
jl
[
-
1
],
self
.
proto
.
cname
())
class
s_object
(
s
tanza
):
class
ObjectStanza
(
S
tanza
):
def
parse
(
self
):
def
parse
(
self
):
self
.
proto
=
ProtoType
(
self
,
retval
=
False
)
self
.
proto
=
ProtoType
(
self
,
retval
=
False
)
self
.
proto
.
obj
=
"x"
+
self
.
proto
.
name
self
.
proto
.
obj
=
"x"
+
self
.
proto
.
name
...
@@ -741,7 +743,7 @@ class s_object(stanza):
...
@@ -741,7 +743,7 @@ class s_object(stanza):
for
i
in
self
.
methods
:
for
i
in
self
.
methods
:
i
.
rstfile
(
fo
,
man
)
i
.
rstfile
(
fo
,
man
)
def
rstmid
(
self
,
fo
,
man
):
def
rstmid
(
self
,
unused_fo
,
unused_
man
):
return
return
def
synopsis
(
self
,
fo
,
man
):
def
synopsis
(
self
,
fo
,
man
):
...
@@ -794,17 +796,17 @@ class s_object(stanza):
...
@@ -794,17 +796,17 @@ class s_object(stanza):
jl
.
append
(
ll
)
jl
.
append
(
ll
)
def
dump
(
self
):
def
dump
(
self
):
super
(
s_object
,
self
)
.
dump
()
super
(
ObjectStanza
,
self
)
.
dump
()
for
i
in
self
.
methods
:
for
i
in
self
.
methods
:
i
.
dump
()
i
.
dump
()
#######################################################################
#######################################################################
class
s_method
(
s
tanza
):
class
MethodStanza
(
S
tanza
):
def
parse
(
self
):
def
parse
(
self
):
p
=
self
.
vcc
.
contents
[
-
1
]
p
=
self
.
vcc
.
contents
[
-
1
]
assert
type
(
p
)
==
s_object
assert
isinstance
(
p
,
ObjectStanza
)
self
.
pfx
=
p
.
proto
.
name
self
.
pfx
=
p
.
proto
.
name
self
.
proto
=
ProtoType
(
self
,
prefix
=
self
.
pfx
)
self
.
proto
=
ProtoType
(
self
,
prefix
=
self
.
pfx
)
if
not
self
.
proto
.
bname
.
startswith
(
"."
):
if
not
self
.
proto
.
bname
.
startswith
(
"."
):
...
@@ -828,18 +830,21 @@ class s_method(stanza):
...
@@ -828,18 +830,21 @@ class s_method(stanza):
#######################################################################
#######################################################################
DISPATCH
=
{
DISPATCH
=
{
"Module"
:
s_module
,
"Module"
:
ModuleStanza
,
"Prefix"
:
s_prefix
,
"Prefix"
:
PrefixStanza
,
"ABI"
:
s_abi
,
"ABI"
:
ABIStanza
,
"Event"
:
s_event
,
"Event"
:
EventStanza
,
"Function"
:
s_function
,
"Function"
:
FunctionStanza
,
"Object"
:
s_object
,
"Object"
:
ObjectStanza
,
"Method"
:
s_method
,
"Method"
:
MethodStanza
,
"Synopsis"
:
s_synopsis
,
"Synopsis"
:
SynopsisStanza
,
}
}
class
vcc
(
object
):
class
vcc
(
object
):
''' Processing context for a single .vcc file '''
def
__init__
(
self
,
inputvcc
,
rstdir
,
outputprefix
):
def
__init__
(
self
,
inputvcc
,
rstdir
,
outputprefix
):
self
.
inputfile
=
inputvcc
self
.
inputfile
=
inputvcc
self
.
rstdir
=
rstdir
self
.
rstdir
=
rstdir
...
@@ -880,7 +885,7 @@ class vcc(object):
...
@@ -880,7 +885,7 @@ class vcc(object):
m
(
toks
,
[
c
[
0
],
" "
.
join
(
c
[
1
:])],
d
.
split
(
'
\n
'
),
self
)
m
(
toks
,
[
c
[
0
],
" "
.
join
(
c
[
1
:])],
d
.
split
(
'
\n
'
),
self
)
inputline
=
None
inputline
=
None
def
tokenize
(
self
,
str
,
seps
=
None
,
quotes
=
None
):
def
tokenize
(
self
,
txt
,
seps
=
None
,
quotes
=
None
):
if
seps
is
None
:
if
seps
is
None
:
seps
=
"[](){},="
seps
=
"[](){},="
if
quotes
is
None
:
if
quotes
is
None
:
...
@@ -889,8 +894,8 @@ class vcc(object):
...
@@ -889,8 +894,8 @@ class vcc(object):
out
=
[]
out
=
[]
i
=
0
i
=
0
inside
=
False
inside
=
False
while
i
<
len
(
str
):
while
i
<
len
(
txt
):
c
=
str
[
i
]
c
=
txt
[
i
]
# print("T", [c], quote, inside, i)
# print("T", [c], quote, inside, i)
i
+=
1
i
+=
1
if
quote
is
not
None
and
c
==
quote
:
if
quote
is
not
None
and
c
==
quote
:
...
@@ -1053,13 +1058,13 @@ class vcc(object):
...
@@ -1053,13 +1058,13 @@ class vcc(object):
fo
.
write
(
"
\n
"
)
fo
.
write
(
"
\n
"
)
for
i
in
self
.
contents
:
for
i
in
self
.
contents
:
if
type
(
i
)
==
s_object
:
if
isinstance
(
i
,
ObjectStanza
)
:
i
.
cstuff
(
fo
,
'c'
)
i
.
cstuff
(
fo
,
'c'
)
i
.
cstuff
(
fx
,
'o'
)
i
.
cstuff
(
fx
,
'o'
)
fx
.
write
(
"/* Functions */
\n
"
)
fx
.
write
(
"/* Functions */
\n
"
)
for
i
in
self
.
contents
:
for
i
in
self
.
contents
:
if
type
(
i
)
==
s_function
:
if
isinstance
(
i
,
FunctionStanza
)
:
i
.
cstuff
(
fo
,
'c'
)
i
.
cstuff
(
fo
,
'c'
)
i
.
cstuff
(
fx
,
'o'
)
i
.
cstuff
(
fx
,
'o'
)
...
...
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