~ubuntu-branches/ubuntu/trusty/boa-constructor/trusty

« back to all changes in this revision

Viewing changes to ExternalLib/WebDAV/App_Common.py

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2007-01-23 21:32:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070123213229-1d9lxp9c4dutjwv5
Add a .desktop file (Closes: #349081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Zope Public License (ZPL) Version 1.0
4
 
# -------------------------------------
5
 
#
6
 
# Copyright (c) Digital Creations.  All rights reserved.
7
 
#
8
 
# This license has been certified as Open Source(tm).
9
 
#
10
 
# Redistribution and use in source and binary forms, with or without
11
 
# modification, are permitted provided that the following conditions are
12
 
# met:
13
 
#
14
 
# 1. Redistributions in source code must retain the above copyright
15
 
#    notice, this list of conditions, and the following disclaimer.
16
 
#
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
20
 
#    distribution.
21
 
#
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.
29
 
#
30
 
# 4. All advertising materials and documentation mentioning
31
 
#    features derived from or use of this software must display
32
 
#    the following acknowledgement:
33
 
#
34
 
#      "This product includes software developed by Digital Creations
35
 
#      for use in the Z Object Publishing Environment
36
 
#      (http://www.zope.org/)."
37
 
#
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.
41
 
#
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.
45
 
#
46
 
# 6. Modified redistributions of any form whatsoever must retain
47
 
#    the following acknowledgment:
48
 
#
49
 
#      "This product includes software developed by Digital Creations
50
 
#      for use in the Z Object Publishing Environment
51
 
#      (http://www.zope.org/)."
52
 
#
53
 
#    Intact (re-)distributions of any official Zope release do not
54
 
#    require an external acknowledgement.
55
 
#
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.
62
 
#
63
 
#
64
 
# Disclaimer
65
 
#
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
77
 
#   SUCH DAMAGE.
78
 
#
79
 
#
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.
83
 
#
84
 
##############################################################################
85
 
 
86
 
"""Commonly used utility functions."""
87
 
 
88
 
__version__='$Revision: 1.1 $'[11:-2]
89
 
 
90
 
import sys, os, time
91
 
from string import rfind
92
 
 
93
 
 
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']
102
 
 
103
 
 
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))
110
 
 
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" % (
117
 
            weekday_full[wd],
118
 
            day, monthname[month],
119
 
            str(year)[2:],
120
 
            hh, mm, ss)
121
 
 
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],
130
 
                                                    year,
131
 
                                                    hh, mm, ss)
132
 
 
133
 
def absattr(attr, c=callable):
134
 
    # Return the absolute value of an attribute,
135
 
    # calling the attr if it is callable.
136
 
    if c(attr):
137
 
        return attr()
138
 
    return attr
139
 
 
140
 
def aq_base(ob, hasattr=hasattr):
141
 
    # Return the aq_base of an object.
142
 
    if hasattr(ob, 'aq_base'):
143
 
        return ob.aq_base
144
 
    return ob
145
 
 
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'):
150
 
        return 0
151
 
    if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
152
 
        return 0
153
 
    if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
154
 
            ob.isTopLevelPrincipiaApplicationObject:
155
 
        return 0
156
 
    return 1
157
 
 
158
 
 
159
 
def package_home(globals_dict):
160
 
    __name__=globals_dict['__name__']
161
 
    m=sys.modules[__name__]
162
 
    if hasattr(m,'__path__'):
163
 
        r=m.__path__[0]
164
 
    elif "." in __name__:
165
 
        r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
166
 
    else:
167
 
        r=__name__
168
 
    return os.path.join(os.getcwd(), r)
169
 
 
170
 
 
171
 
def attrget(o,name,default):
172
 
    if hasattr(o,name): return getattr(o,name)
173
 
    return default
174
 
 
175
 
def Dictionary(**kw): return kw # Sorry Guido
 
1
##############################################################################
 
2
#
 
3
# Zope Public License (ZPL) Version 1.0
 
4
# -------------------------------------
 
5
#
 
6
# Copyright (c) Digital Creations.  All rights reserved.
 
7
#
 
8
# This license has been certified as Open Source(tm).
 
9
#
 
10
# Redistribution and use in source and binary forms, with or without
 
11
# modification, are permitted provided that the following conditions are
 
12
# met:
 
13
#
 
14
# 1. Redistributions in source code must retain the above copyright
 
15
#    notice, this list of conditions, and the following disclaimer.
 
16
#
 
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
 
20
#    distribution.
 
21
#
 
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.
 
29
#
 
30
# 4. All advertising materials and documentation mentioning
 
31
#    features derived from or use of this software must display
 
32
#    the following acknowledgement:
 
33
#
 
34
#      "This product includes software developed by Digital Creations
 
35
#      for use in the Z Object Publishing Environment
 
36
#      (http://www.zope.org/)."
 
37
#
 
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.
 
41
#
 
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.
 
45
#
 
46
# 6. Modified redistributions of any form whatsoever must retain
 
47
#    the following acknowledgment:
 
48
#
 
49
#      "This product includes software developed by Digital Creations
 
50
#      for use in the Z Object Publishing Environment
 
51
#      (http://www.zope.org/)."
 
52
#
 
53
#    Intact (re-)distributions of any official Zope release do not
 
54
#    require an external acknowledgement.
 
55
#
 
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.
 
62
#
 
63
#
 
64
# Disclaimer
 
65
#
 
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
 
77
#   SUCH DAMAGE.
 
78
#
 
79
#
 
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.
 
83
#
 
84
##############################################################################
 
85
 
 
86
"""Commonly used utility functions."""
 
87
 
 
88
__version__='$Revision: 1.1 $'[11:-2]
 
89
 
 
90
import sys, os, time
 
91
from string import rfind
 
92
 
 
93
 
 
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']
 
102
 
 
103
 
 
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))
 
110
 
 
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" % (
 
117
            weekday_full[wd],
 
118
            day, monthname[month],
 
119
            str(year)[2:],
 
120
            hh, mm, ss)
 
121
 
 
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],
 
130
                                                    year,
 
131
                                                    hh, mm, ss)
 
132
 
 
133
def absattr(attr, c=callable):
 
134
    # Return the absolute value of an attribute,
 
135
    # calling the attr if it is callable.
 
136
    if c(attr):
 
137
        return attr()
 
138
    return attr
 
139
 
 
140
def aq_base(ob, hasattr=hasattr):
 
141
    # Return the aq_base of an object.
 
142
    if hasattr(ob, 'aq_base'):
 
143
        return ob.aq_base
 
144
    return ob
 
145
 
 
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'):
 
150
        return 0
 
151
    if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
 
152
        return 0
 
153
    if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
 
154
            ob.isTopLevelPrincipiaApplicationObject:
 
155
        return 0
 
156
    return 1
 
157
 
 
158
 
 
159
def package_home(globals_dict):
 
160
    __name__=globals_dict['__name__']
 
161
    m=sys.modules[__name__]
 
162
    if hasattr(m,'__path__'):
 
163
        r=m.__path__[0]
 
164
    elif "." in __name__:
 
165
        r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
 
166
    else:
 
167
        r=__name__
 
168
    return os.path.join(os.getcwd(), r)
 
169
 
 
170
 
 
171
def attrget(o,name,default):
 
172
    if hasattr(o,name): return getattr(o,name)
 
173
    return default
 
174
 
 
175
def Dictionary(**kw): return kw # Sorry Guido