• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Zope / 3956162881

pending completion
3956162881

push

github

Michael Howitz
Update to deprecation warning free releases.

4401 of 7036 branches covered (62.55%)

Branch coverage included in aggregate %.

27161 of 31488 relevant lines covered (86.26%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.34
/src/App/Common.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE
11
#
12
##############################################################################
13
"""Commonly used utility functions."""
1✔
14

15
import os
1✔
16
import sys
1✔
17

18
from Acquisition import aq_base
1✔
19
from Acquisition import aq_parent
1✔
20
from zope.deferredimport import deprecated
1✔
21

22

23
deprecated(
1✔
24
    'Please import from zope.datetime.'
25
    ' This backwards compatibility import will go away in Zope 6.',
26
    weekday_abbr='zope.datetime:weekday_abbr',
27
    weekday_full='zope.datetime:weekday_full',
28
    monthname='zope.datetime:monthname',
29
    iso8601_date='zope.datetime:iso8601_date',
30
    rfc850_date='zope.datetime:rfc850_date',
31
    rfc1123_date='zope.datetime:rfc1123_date',
32
)
33

34
deprecated(
1✔
35
    'Please import from os.path.'
36
    ' This backwards compatibility import will go away in Zope 6.',
37
    realpath='os.path:realpath',
38
)
39

40
deprecated(
1✔
41
    'Please import time directly.'
42
    ' This backwards compatibility import will go away in Zope 6.',
43
    time='time',
44
)
45

46

47
attrget = getattr
1✔
48

49

50
def absattr(attr, callable=callable):
1✔
51
    # Return the absolute value of an attribute,
52
    # calling the attr if it is callable.
53
    if callable(attr):
×
54
        return attr()
×
55
    return attr
×
56

57

58
def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
1✔
59
    # Return true if this object is not considered to be
60
    # a direct subobject of its acquisition parent
61
    # Note that this method is misnamed since parents can (and do)
62
    # spoof it. It is not a true measure of whether something is
63
    # acquired, it relies on the parent's parent-ness exclusively
64
    import warnings
×
65
    warnings.warn(
×
66
        "The function `is_acquired` is deprecated "
67
        "and will be removed in Zope 6.",
68
        DeprecationWarning)
69
    if not hasattr(ob, '__parent__'):
×
70
        # We can't be acquired if we don't have an __parent__
71
        return 0
×
72

73
    parent = aq_base(aq_parent(ob))
×
74
    absId = absattr(ob.id)
×
75

76
    if hasattr(parent, absId):
×
77
        # Consider direct attributes not acquired
78
        return 0
×
79

80
    if hasattr(parent, '__getitem__'):
×
81
        # Use __getitem__ as opposed to has_key to avoid TTW namespace
82
        # issues, and to support the most minimal mapping objects
83
        try:
×
84
            # We assume that getitem will not acquire which
85
            # is the standard behavior for Zope objects
86
            if aq_base(aq_parent(ob)[absId]) is aq_base(ob):
×
87
                # This object is an item of the aq_parent, its not acquired
88
                return 0
×
89
        except KeyError:
×
90
            pass
×
91

92
    if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
×
93
            ob.isTopLevelPrincipiaApplicationObject:
94
        # This object the top level
95
        return 0
×
96
    return 1  # This object is acquired by our measure
×
97

98

99
def package_home(globals_dict):
1✔
100
    __name__ = globals_dict['__name__']
1✔
101
    m = sys.modules[__name__]
1✔
102
    if hasattr(m, '__path__'):
1✔
103
        r = m.__path__[0]
1✔
104
    elif "." in __name__:
1!
105
        r = sys.modules[__name__[:__name__.rfind('.')]].__path__[0]
1✔
106
    else:
107
        r = __name__
×
108
    return os.path.abspath(r)
1✔
109

110

111
def Dictionary(**kw):
1✔
112
    import warnings
×
113
    warnings.warn(
×
114
        "The function `Dictionary` is deprecated "
115
        "and will be removed in Zope 6.",
116
        DeprecationWarning)
117
    return kw  # Sorry Guido
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc