1
##############################################################################
3
# Zope Public License (ZPL) Version 1.0
4
# -------------------------------------
6
# Copyright (c) Digital Creations. All rights reserved.
8
# This license has been certified as Open Source(tm).
10
# Redistribution and use in source and binary forms, with or without
11
# modification, are permitted provided that the following conditions are
14
# 1. Redistributions in source code must retain the above copyright
15
# notice, this list of conditions, and the following disclaimer.
17
# 2. Redistributions in binary form must reproduce the above copyright
18
# notice, this list of conditions, and the following disclaimer in
19
# the documentation and/or other materials provided with the
22
# 3. Digital Creations requests that attribution be given to Zope
23
# in any manner possible. Zope includes a "Powered by Zope"
24
# button that is installed by default. While it is not a license
25
# violation to remove this button, it is requested that the
26
# attribution remain. A significant investment has been put
27
# into Zope, and this effort will continue if the Zope community
28
# continues to grow. This is one way to assure that growth.
30
# 4. All advertising materials and documentation mentioning
31
# features derived from or use of this software must display
32
# the following acknowledgement:
34
# "This product includes software developed by Digital Creations
35
# for use in the Z Object Publishing Environment
36
# (http://www.zope.org/)."
38
# In the event that the product being advertised includes an
39
# intact Zope distribution (with copyright and license included)
40
# then this clause is waived.
42
# 5. Names associated with Zope or Digital Creations must not be used to
43
# endorse or promote products derived from this software without
44
# prior written permission from Digital Creations.
46
# 6. Modified redistributions of any form whatsoever must retain
47
# the following acknowledgment:
49
# "This product includes software developed by Digital Creations
50
# for use in the Z Object Publishing Environment
51
# (http://www.zope.org/)."
53
# Intact (re-)distributions of any official Zope release do not
54
# require an external acknowledgement.
56
# 7. Modifications are encouraged but must be packaged separately as
57
# patches to official Zope releases. Distributions that do not
58
# clearly separate the patches from the original work must be clearly
59
# labeled as unofficial distributions. Modifications which do not
60
# carry the name Zope may be packaged in any form, as long as they
61
# conform to all of the clauses above.
66
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
67
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
70
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
71
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
72
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
73
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
75
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
76
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80
# This software consists of contributions made by Digital Creations and
81
# many individuals on behalf of Digital Creations. Specific
82
# attributions are listed in the accompanying credits file.
84
##############################################################################
86
"""Commonly used utility functions."""
88
__version__='$Revision: 1.1 $'[11:-2]
91
from string import rfind
94
# These are needed because the various date formats below must
95
# be in english per the RFCs. That means we can't use strftime,
96
# which is affected by different locale settings.
97
weekday_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
98
weekday_full = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
99
'Friday', 'Saturday', 'Sunday']
100
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
101
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
104
def iso8601_date(ts=None):
105
# Return an ISO 8601 formatted date string, required
106
# for certain DAV properties.
107
# '2000-11-10T16:21:09-08:00
108
if ts is None: ts=time.time()
109
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts))
111
def rfc850_date(ts=None):
112
# Return an HTTP-date formatted date string.
113
# 'Friday, 10-Nov-00 16:21:09 GMT'
114
if ts is None: ts=time.time()
115
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
116
return "%s, %02d-%3s-%2s %02d:%02d:%02d GMT" % (
118
day, monthname[month],
122
def rfc1123_date(ts=None):
123
# Return an RFC 1123 format date string, required for
124
# use in HTTP Date headers per the HTTP 1.1 spec.
125
# 'Fri, 10 Nov 2000 16:21:09 GMT'
126
if ts is None: ts=time.time()
127
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
128
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekday_abbr[wd],
129
day, monthname[month],
133
def absattr(attr, c=callable):
134
# Return the absolute value of an attribute,
135
# calling the attr if it is callable.
140
def aq_base(ob, hasattr=hasattr):
141
# Return the aq_base of an object.
142
if hasattr(ob, 'aq_base'):
146
def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
147
# Return true if this object is not a direct
148
# subobject of its aq_parent object.
149
if not hasattr(ob, 'aq_parent'):
151
if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
153
if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
154
ob.isTopLevelPrincipiaApplicationObject:
159
def package_home(globals_dict):
160
__name__=globals_dict['__name__']
161
m=sys.modules[__name__]
162
if hasattr(m,'__path__'):
164
elif "." in __name__:
165
r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
168
return os.path.join(os.getcwd(), r)
171
def attrget(o,name,default):
172
if hasattr(o,name): return getattr(o,name)
175
def Dictionary(**kw): return kw # Sorry Guido
1
##############################################################################
3
# Zope Public License (ZPL) Version 1.0
4
# -------------------------------------
6
# Copyright (c) Digital Creations. All rights reserved.
8
# This license has been certified as Open Source(tm).
10
# Redistribution and use in source and binary forms, with or without
11
# modification, are permitted provided that the following conditions are
14
# 1. Redistributions in source code must retain the above copyright
15
# notice, this list of conditions, and the following disclaimer.
17
# 2. Redistributions in binary form must reproduce the above copyright
18
# notice, this list of conditions, and the following disclaimer in
19
# the documentation and/or other materials provided with the
22
# 3. Digital Creations requests that attribution be given to Zope
23
# in any manner possible. Zope includes a "Powered by Zope"
24
# button that is installed by default. While it is not a license
25
# violation to remove this button, it is requested that the
26
# attribution remain. A significant investment has been put
27
# into Zope, and this effort will continue if the Zope community
28
# continues to grow. This is one way to assure that growth.
30
# 4. All advertising materials and documentation mentioning
31
# features derived from or use of this software must display
32
# the following acknowledgement:
34
# "This product includes software developed by Digital Creations
35
# for use in the Z Object Publishing Environment
36
# (http://www.zope.org/)."
38
# In the event that the product being advertised includes an
39
# intact Zope distribution (with copyright and license included)
40
# then this clause is waived.
42
# 5. Names associated with Zope or Digital Creations must not be used to
43
# endorse or promote products derived from this software without
44
# prior written permission from Digital Creations.
46
# 6. Modified redistributions of any form whatsoever must retain
47
# the following acknowledgment:
49
# "This product includes software developed by Digital Creations
50
# for use in the Z Object Publishing Environment
51
# (http://www.zope.org/)."
53
# Intact (re-)distributions of any official Zope release do not
54
# require an external acknowledgement.
56
# 7. Modifications are encouraged but must be packaged separately as
57
# patches to official Zope releases. Distributions that do not
58
# clearly separate the patches from the original work must be clearly
59
# labeled as unofficial distributions. Modifications which do not
60
# carry the name Zope may be packaged in any form, as long as they
61
# conform to all of the clauses above.
66
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
67
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
70
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
71
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
72
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
73
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
75
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
76
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80
# This software consists of contributions made by Digital Creations and
81
# many individuals on behalf of Digital Creations. Specific
82
# attributions are listed in the accompanying credits file.
84
##############################################################################
86
"""Commonly used utility functions."""
88
__version__='$Revision: 1.1 $'[11:-2]
91
from string import rfind
94
# These are needed because the various date formats below must
95
# be in english per the RFCs. That means we can't use strftime,
96
# which is affected by different locale settings.
97
weekday_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
98
weekday_full = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
99
'Friday', 'Saturday', 'Sunday']
100
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
101
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
104
def iso8601_date(ts=None):
105
# Return an ISO 8601 formatted date string, required
106
# for certain DAV properties.
107
# '2000-11-10T16:21:09-08:00
108
if ts is None: ts=time.time()
109
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts))
111
def rfc850_date(ts=None):
112
# Return an HTTP-date formatted date string.
113
# 'Friday, 10-Nov-00 16:21:09 GMT'
114
if ts is None: ts=time.time()
115
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
116
return "%s, %02d-%3s-%2s %02d:%02d:%02d GMT" % (
118
day, monthname[month],
122
def rfc1123_date(ts=None):
123
# Return an RFC 1123 format date string, required for
124
# use in HTTP Date headers per the HTTP 1.1 spec.
125
# 'Fri, 10 Nov 2000 16:21:09 GMT'
126
if ts is None: ts=time.time()
127
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
128
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekday_abbr[wd],
129
day, monthname[month],
133
def absattr(attr, c=callable):
134
# Return the absolute value of an attribute,
135
# calling the attr if it is callable.
140
def aq_base(ob, hasattr=hasattr):
141
# Return the aq_base of an object.
142
if hasattr(ob, 'aq_base'):
146
def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
147
# Return true if this object is not a direct
148
# subobject of its aq_parent object.
149
if not hasattr(ob, 'aq_parent'):
151
if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
153
if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
154
ob.isTopLevelPrincipiaApplicationObject:
159
def package_home(globals_dict):
160
__name__=globals_dict['__name__']
161
m=sys.modules[__name__]
162
if hasattr(m,'__path__'):
164
elif "." in __name__:
165
r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
168
return os.path.join(os.getcwd(), r)
171
def attrget(o,name,default):
172
if hasattr(o,name): return getattr(o,name)
175
def Dictionary(**kw): return kw # Sorry Guido