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
fc3cf7da
Commit
fc3cf7da
authored
Nov 28, 2003
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reimplemented method objects to use new-style extension classes.
parent
16e11ef3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
+128
-0
lib/python/MethodObject/_MethodObject.c
lib/python/MethodObject/_MethodObject.c
+58
-0
lib/python/MethodObject/__init__.py
lib/python/MethodObject/__init__.py
+1
-0
lib/python/MethodObject/setup.py
lib/python/MethodObject/setup.py
+22
-0
lib/python/MethodObject/tests.py
lib/python/MethodObject/tests.py
+47
-0
No files found.
lib/python/MethodObject/_MethodObject.c
0 → 100644
View file @
fc3cf7da
/*****************************************************************************
Copyright (c) 1996-2002 Zope Corporation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
****************************************************************************/
#include "ExtensionClass.h"
static
PyObject
*
of
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
inst
;
if
(
PyArg_Parse
(
args
,
"O"
,
&
inst
))
return
PyECMethod_New
(
self
,
inst
);
else
return
NULL
;
}
struct
PyMethodDef
Method_methods
[]
=
{
{
"__of__"
,(
PyCFunction
)
of
,
0
,
""
},
{
NULL
,
NULL
}
/* sentinel */
};
static
struct
PyMethodDef
methods
[]
=
{{
NULL
,
NULL
}};
void
init_MethodObject
(
void
)
{
PyObject
*
m
,
*
d
;
PURE_MIXIN_CLASS
(
Method
,
"Base class for objects that want to be treated as methods
\n
"
"
\n
"
"The method class provides a method, __of__, that
\n
"
"binds an object to an instance. If a method is a subobject
\n
"
"of an extension-class instance, the the method will be bound
\n
"
"to the instance and when the resulting object is called, it
\n
"
"will call the method and pass the instance in addition to
\n
"
"other arguments. It is the responsibility of Method objects
\n
"
"to implement (or inherit) a __call__ method.
\n
"
,
Method_methods
);
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"_MethodObject"
,
methods
,
"Method-object mix-in class module
\n\n
"
"$Id: _MethodObject.c,v 1.2 2003/11/28 16:45:06 jim Exp $
\n
"
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
PyExtensionClass_Export
(
d
,
"Method"
,
MethodType
);
}
lib/python/MethodObject/__init__.py
0 → 100644
View file @
fc3cf7da
from
_MethodObject
import
*
lib/python/MethodObject/setup.py
0 → 100644
View file @
fc3cf7da
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from
distutils.core
import
setup
,
Extension
setup
(
name
=
"_MethodObject"
,
version
=
"2.0"
,
ext_modules
=
[
Extension
(
"_MethodObject"
,
[
"_MethodObject.c"
],
include_dirs
=
[
'.'
,
'../ExtensionClass'
],
depends
=
[
'../ExtensionClass/ExtensionClass.h'
]),
])
lib/python/MethodObject/tests.py
0 → 100644
View file @
fc3cf7da
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""XXX short summary goes here.
$Id: tests.py,v 1.2 2003/11/28 16:45:06 jim Exp $
"""
import
unittest
from
doctest
import
DocTestSuite
def
test_xxx
():
"""
>>> from ExtensionClass import Base
>>> from MethodObject import Method
>>> class foo(Method):
... def __call__(self, ob, *args, **kw):
... print 'called', ob, args, kw
>>> class bar(Base):
... def __repr__(self):
... return "bar()"
... hi = foo()
>>> x = bar()
>>> hi = x.hi
>>> hi(1,2,3,name='spam')
called bar() (1, 2, 3) {'name': 'spam'}
"""
def
test_suite
():
return
unittest
.
TestSuite
((
DocTestSuite
(),
))
if
__name__
==
'__main__'
:
unittest
.
main
()
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