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
4e038901
Commit
4e038901
authored
Dec 04, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
untabified.
parent
5a85f09e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
54 deletions
+44
-54
lib/Components/ExtensionClass/ComputedAttribute.py
lib/Components/ExtensionClass/ComputedAttribute.py
+4
-14
lib/Components/ExtensionClass/test/test_Sync.py
lib/Components/ExtensionClass/test/test_Sync.py
+13
-13
lib/Components/ExtensionClass/test/test_ThreadLock.py
lib/Components/ExtensionClass/test/test_ThreadLock.py
+25
-25
lib/Components/ExtensionClass/test/test_method_hook.py
lib/Components/ExtensionClass/test/test_method_hook.py
+2
-2
No files found.
lib/Components/ExtensionClass/ComputedAttribute.py
View file @
4e038901
#!/bin/env python
##############################################################################
#
# Copyright
...
...
@@ -77,8 +76,8 @@ called automatically, if it has one.
This module provides a simple computed attribute implementation and
an example of its usage.
$Id: ComputedAttribute.py,v 1.
1 1998/04/07 16:43:21
jim Exp $'''
__version__
=
'$Revision: 1.
1
$'
[
11
:
-
2
]
$Id: ComputedAttribute.py,v 1.
2 1998/12/04 20:57:46
jim Exp $'''
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
import
ExtensionClass
...
...
@@ -98,18 +97,9 @@ if __name__ == "__main__":
class
point
(
ExtensionClass
.
Base
):
def
__init__
(
self
,
x
,
y
):
self
.
x
,
self
.
y
=
x
,
y
def
__init__
(
self
,
x
,
y
):
self
.
x
,
self
.
y
=
x
,
y
radius
=
ComputedAttribute
(
lambda
self
:
sqrt
(
self
.
x
**
2
+
self
.
y
**
2
))
radius
=
ComputedAttribute
(
lambda
self
:
sqrt
(
self
.
x
**
2
+
self
.
y
**
2
))
p
=
point
(
2
,
2
)
print
p
.
radius
##############################################################################
#
# $Log: ComputedAttribute.py,v $
# Revision 1.1 1998/04/07 16:43:21 jim
# *** empty log message ***
#
#
lib/Components/ExtensionClass/test/test_Sync.py
View file @
4e038901
...
...
@@ -8,28 +8,28 @@ from time import sleep
class
P
(
Synchronized
):
def
__init__
(
self
,
*
args
,
**
kw
):
self
.
count
=
0
self
.
count
=
0
def
inc
(
self
):
c
=
self
.
count
sleep
(
rand
()
/
327680.0
)
self
.
count
=
self
.
count
+
1
return
c
,
self
.
count
c
=
self
.
count
sleep
(
rand
()
/
327680.0
)
self
.
count
=
self
.
count
+
1
return
c
,
self
.
count
def
incn
(
self
,
n
):
c
=
self
.
count
for
i
in
range
(
n
):
self
.
inc
()
return
c
,
self
.
count
c
=
self
.
count
for
i
in
range
(
n
):
self
.
inc
()
return
c
,
self
.
count
p
=
P
(
1
,
2
,
spam
=
3
)
def
test
():
for
i
in
range
(
10
):
n
=
3
old
,
new
=
p
.
incn
(
n
)
print
old
,
new
if
old
+
n
!=
new
:
print
'oops'
n
=
3
old
,
new
=
p
.
incn
(
n
)
print
old
,
new
if
old
+
n
!=
new
:
print
'oops'
for
i
in
range
(
10
):
thread
.
start_new_thread
(
test
,())
...
...
lib/Components/ExtensionClass/test/test_ThreadLock.py
View file @
4e038901
...
...
@@ -10,44 +10,44 @@ with_lock=1
class
P
(
Base
):
def
__oldcall_method__
(
self
,
f
,
a
,
k
=
{}):
if
with_lock
:
try
:
lock
=
self
.
lock
except
AttributeError
:
return
apply
(
f
,
a
,
k
)
else
:
return
apply
(
f
,
a
,
k
)
try
:
lock
.
acquire
()
return
apply
(
f
,
a
,
k
)
finally
:
lock
.
release
()
if
with_lock
:
try
:
lock
=
self
.
lock
except
AttributeError
:
return
apply
(
f
,
a
,
k
)
else
:
return
apply
(
f
,
a
,
k
)
try
:
lock
.
acquire
()
return
apply
(
f
,
a
,
k
)
finally
:
lock
.
release
()
__call_method__
=
apply
def
__init__
(
self
,
*
args
,
**
kw
):
self
.
count
=
0
if
with_lock
:
self
.
lock
=
lock
=
ThreadLock
.
allocate_lock
()
self
.
__call_method__
=
lock
.
guarded_apply
self
.
count
=
0
if
with_lock
:
self
.
lock
=
lock
=
ThreadLock
.
allocate_lock
()
self
.
__call_method__
=
lock
.
guarded_apply
def
inc
(
self
):
c
=
self
.
count
sleep
(
rand
()
/
32768.0
)
self
.
count
=
self
.
count
+
1
return
c
,
self
.
count
c
=
self
.
count
sleep
(
rand
()
/
32768.0
)
self
.
count
=
self
.
count
+
1
return
c
,
self
.
count
def
incn
(
self
,
n
):
c
=
self
.
count
for
i
in
range
(
n
):
self
.
inc
()
return
c
,
self
.
count
c
=
self
.
count
for
i
in
range
(
n
):
self
.
inc
()
return
c
,
self
.
count
p
=
P
(
1
,
2
,
spam
=
3
)
def
test
():
for
i
in
range
(
10
):
n
=
3
old
,
new
=
p
.
incn
(
n
)
print
old
,
new
if
old
+
n
!=
new
:
print
'oops'
n
=
3
old
,
new
=
p
.
incn
(
n
)
print
old
,
new
if
old
+
n
!=
new
:
print
'oops'
for
i
in
range
(
10
):
thread
.
start_new_thread
(
test
,())
...
...
lib/Components/ExtensionClass/test/test_method_hook.py
View file @
4e038901
...
...
@@ -4,8 +4,8 @@ import ExtensionClass
class
C
(
ExtensionClass
.
Base
):
def
__call_method__
(
self
,
meth
,
args
,
kw
=
{}):
print
'give us a hook, hook, hook...'
apply
(
meth
,
args
,
kw
)
print
'give us a hook, hook, hook...'
apply
(
meth
,
args
,
kw
)
def
hi
(
self
,
*
args
,
**
kw
):
print
self
,
args
,
kw
...
...
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