Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
159ed39c
Commit
159ed39c
authored
Feb 22, 1999
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added separate interface for calling objects with just a mapping
parent
dd034bb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
lib/python/ZPublisher/mapply.py
lib/python/ZPublisher/mapply.py
+71
-0
No files found.
lib/python/ZPublisher/mapply.py
0 → 100644
View file @
159ed39c
"""Provide an apply-like facility that works with any mapping object
"""
def
default_call_object
(
object
,
args
,
context
):
result
=
apply
(
object
,
args
)
# Type s<cr> to step into published object.
return
result
def
default_missing_name
(
name
,
context
):
raise
TypeError
,
'argument %s was ommitted'
%
name
def
default_handle_class
(
klass
,
context
):
if
hasattr
(
klass
,
'__init__'
):
f
=
klass
.
__init__
.
im_func
c
=
f
.
func_code
names
=
c
.
co_varnames
[
1
:
c
.
co_argcount
]
return
klass
,
names
,
f
.
func_defaults
else
:
return
klass
,
(),
()
def
mapply
(
object
,
positional
=
(),
keyword
=
{},
debug
=
None
,
maybe
=
None
,
missing_name
=
default_missing_name
,
handle_class
=
default_handle_class
,
context
=
None
):
if
hasattr
(
object
,
'__bases__'
):
f
,
names
,
defaults
=
handle_class
(
object
,
context
)
else
:
f
=
object
im
=
0
if
hasattr
(
f
,
'im_func'
):
im
=
1
elif
not
hasattr
(
f
,
'func_defaults'
):
if
hasattr
(
f
,
'__call__'
):
f
=
f
.
__call__
if
hasattr
(
f
,
'im_func'
):
im
=
1
elif
not
hasattr
(
f
,
'func_defaults'
)
and
maybe
:
return
object
elif
maybe
:
return
object
if
im
:
f
=
f
.
im_func
c
=
f
.
func_code
defaults
=
f
.
func_defaults
names
=
c
.
co_varnames
[
1
:
c
.
co_argcount
]
else
:
defaults
=
f
.
func_defaults
c
=
f
.
func_code
names
=
c
.
co_varnames
[:
c
.
co_argcount
]
nargs
=
len
(
names
)
if
positional
:
if
len
(
positional
)
>
nargs
:
raise
TypeError
,
'too many arguments'
args
=
list
(
positional
)
else
:
args
=
[]
get
=
keyword
.
get
nrequired
=
len
(
names
)
-
(
len
(
defaults
or
()))
for
index
in
range
(
len
(
args
),
len
(
names
)):
name
=
names
[
index
]
v
=
get
(
name
,
args
)
if
v
is
args
:
if
index
<
nrequired
:
v
=
missing_name
(
name
,
context
)
else
:
v
=
defaults
[
index
-
nrequired
]
args
.
append
(
v
)
args
=
tuple
(
args
)
if
debug
is
not
None
:
return
debug
(
object
,
args
,
context
)
else
:
return
apply
(
object
,
args
)
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