<commit_before>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# All rights reserved
#
import mint
from mint_server import MintServer

class ShimMintClient(mint.MintClient):
    _allowPrivate = True # enable all private methods of MintClient
    def __init__(self, cfg, authToken):
        self.server = ShimServerProxy(cfg, authToken)
        self._cfg = cfg

    def getCfg(self):
        return self._cfg

class _ShimMethod(mint._Method):
    def __init__(self, server, authToken, name):
        self._server = server
        self._authToken = authToken
        self._name = name

    def __repr__(self):
        return "<mint._ShimMethod(%r)>" % (self._name)

    def __call__(self, *args):
        isException, result = self._server.callWrapper(self._name, self._authToken, args)

        if not isException:
            return result
        else:
            self.handleError(result)

class ShimServerProxy(mint.ServerProxy):
    def __init__(self, cfg, authToken):
        self._cfg = cfg
        self._authToken = authToken
        self._server = MintServer(self._cfg, allowPrivate = True)

    def __getattr__(self, name):
        return _ShimMethod(self._server, self._authToken, name)

    def __repr__(self):
        return "ShimServerProxy(%s, %s)" % (self._cfg, self._authToken)

    def __str__(self):
        return self.__repr__()
<commit_msg>weaken reference to redundant mintServer refernces in shim methods<commit_after>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# All rights reserved
#
import mint
import weakref
from mint_server import MintServer

class ShimMintClient(mint.MintClient):
    _allowPrivate = True # enable all private methods of MintClient
    def __init__(self, cfg, authToken):
        self.server = ShimServerProxy(cfg, authToken)
        self._cfg = cfg

    def getCfg(self):
        return self._cfg

class _ShimMethod(mint._Method, object):
    weakRefs = ('_server',)
    def __init__(self, server, authToken, name):
        self._server = server
        self._authToken = authToken
        self._name = name

    def __repr__(self):
        return "<mint._ShimMethod(%r)>" % (self._name)

    def __call__(self, *args):
        isException, result = self._server.callWrapper(self._name,
                                                       self._authToken, args)

        if not isException:
            return result
        else:
            self.handleError(result)

    def __getattribute__(self, name):
        if name in _ShimMethod.weakRefs:
            return object.__getattribute__(self, name)()
        return object.__getattribute__(self, name)

    def __setattr__(self, name, val):
        if name in _ShimMethod.weakRefs and not isinstance(val, weakref.ref):
            return object.__setattr__(self, name, weakref.ref(val))
        return object.__setattr__(self, name, val)

class ShimServerProxy(mint.ServerProxy):
    def __init__(self, cfg, authToken):
        self._cfg = cfg
        self._authToken = authToken
        self._server = MintServer(self._cfg, allowPrivate = True)

    def __getattr__(self, name):
        return _ShimMethod(self._server, self._authToken, name)

    def __repr__(self):
        return "ShimServerProxy(%s, %s)" % (self._cfg, self._authToken)

    def __str__(self):
        return self.__repr__()

{'fraction_non_alphanumeric': 0.09808685089583966, 'fraction_numerical': 0.004858791375645309, 'mean_word_length': 2.738933030646992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '872966', 'n_tokens_mistral': 1004, 'n_tokens_neox': 959, 'n_words': 252}