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

zopefoundation / Zope / 13615201221

01 Mar 2025 12:26PM UTC coverage: 82.335%. Remained the same
13615201221

push

github

web-flow
Drop pkg_resources usage (#1253)

* chore: replace pkg_resources with importlib.metadata

* Update CHANGES

* Apply pre-commit code formatting

* - move dependencies around, importlib-metadata is now a hard dependency

* - undo version pin juggling

importlib.metadata is part of the standard library. The version pin is
only needed because some dependencies want to pull importlib-metadata,
so that non-standard package is indeed just an indirect dependency.

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Jens Vagelpohl <jens@plyp.com>

3531 of 6001 branches covered (58.84%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 3 files covered. (100.0%)

28099 of 32415 relevant lines covered (86.69%)

0.87 hits per line

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

24.0
/src/App/CacheManager.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
"""Cache management support.
14

15
This class is mixed into the application manager in App.ApplicationManager.
16
"""
17

18
from AccessControl.class_init import InitializeClass
1✔
19
from Acquisition import aq_parent
1✔
20

21

22
class CacheManager:
1✔
23
    """Cache management mix-in
24
    """
25

26
    def _getDB(self):
1✔
27
        try:
1✔
28
            return self._p_jar.db()
1✔
29
        except AttributeError:
×
30
            return aq_parent(self)._p_jar.db()
×
31

32
    def cache_size(self):
1✔
33
        db = self._getDB()
1✔
34
        return db.getCacheSize()
1✔
35

36
    def cache_detail(self, REQUEST=None):
1✔
37
        """
38
        Returns the name of the classes of the objects in the cache
39
        and the number of objects in the cache for each class.
40
        """
41
        detail = self._getDB().cacheDetail()
×
42
        if REQUEST is not None:
×
43
            # format as text
44
            REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
×
45
            return '\n'.join(
×
46
                ['%6d %s' % (count, name) for name, count in detail])
47
        # raw
48
        return detail
×
49

50
    def cache_extreme_detail(self, REQUEST=None):
1✔
51
        """
52
        Returns information about each object in the cache.
53
        """
54
        detail = self._getDB().cacheExtremeDetail()
×
55
        if REQUEST is not None:
×
56
            # sort the list.
57
            lst = [((dict['conn_no'], dict['oid']), dict) for dict in detail]
×
58
            # format as text.
59
            res = [
×
60
                '# Table shows connection number, oid, refcount, state, '
61
                'and class.',
62
                '# States: L = loaded, G = ghost, C = changed']
63
            for sortkey, dict in lst:
×
64
                id = dict.get('id', None)
×
65
                if id:
×
66
                    idinfo = ' (%s)' % id
×
67
                else:
68
                    idinfo = ''
×
69
                s = dict['state']
×
70
                if s == 0:
×
71
                    state = 'L'  # loaded
×
72
                elif s == 1:
×
73
                    state = 'C'  # changed
×
74
                else:
75
                    state = 'G'  # ghost
×
76
                res.append('%d %-34s %6d %s %s%s' % (
×
77
                    dict['conn_no'], repr(dict['oid']), dict['rc'],
78
                    state, dict['klass'], idinfo))
79
            REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
×
80
            return '\n'.join(res)
×
81
        else:
82
            # raw
83
            return detail
×
84

85

86
InitializeClass(CacheManager)
1✔
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