<commit_before>"""
Created on Feb 16, 2014

@author: <NAME>
"""
import maya.cmds as cmds
from collections import Mapping
import weakref
import sys
from mGui.properties import LateBoundProperty, MGuiAttributeError
import maya.utils as utils

# these are primarily intended for debugging.
# Generally you want to break on access failure, since the Binding
# will then invalidate itself and not run again, but you don't want
# to break on bind failure, so the GUI can run without crashing
# Use this with caution, since they are effectively globals

BREAK_ON_ACCESS_FAILURE = True  # break when an accessor fails (eg, a deleted object)
BREAK_ON_BIND_FAILURE = True  # break when a binding fails (instead of silently deleting bad binding)


class BindingError(ValueError):
    pass


class Accessor(object):
    """
    An Accessor abstracts the details of getting or setting an object property,
    so that calling code can get or set values without knowing the precise
    mechanism involved.

    The base Accessor class works on plain python objects. There are derived
    classes for PyNode, maya cmds strings, dictionaries and get-set methods.

    In most cases the <Target> field is a weakref rather than a regular object
    reference. This prevents a binding from keeping an object alive in memory if
    it is not accessed anywhere else.  Some classes (such as dictionaries or datettimes)
    cannot be weak referenced so these are stored as ordinary objects.

    Truth-testing an accessor returns true if the Accessors <Target> exists.
    """

    def __init__(self, datum, fieldName):
        try:
            self.Target = weakref.proxy(datum)
        except TypeError:
            self.Target = datum
        self.FieldName = fieldName

    def _set(self, *args, **kwargs):
        setattr(self.Target, self.FieldName, args[0])

    def _get(self, *args, **kwargs):
        return getattr(self.Target, self.FieldName)

    def push(self, *args, **kwargs):
        """
        Set the value in <args> on <Target.FieldName>. Return true if the set
        was done without excepting.

        If BREAK_ON_ACCESS_FAILURE is true, pass any exceptions; otherwise they
        are silenly ignored
        """
        try:
            self._set(*args, **kwargs)
            return True
        except MGuiAttributeError:
            cmds.warning("Slent MGUI fail!")
            return False
        except:
            if BREAK_ON_ACCESS_FAILURE:
                raise
            else:
                return False

    def pull(self, *args, **kwargs):
        """
        Returns the value from <Target.Fieldname>

        If BREAK_ON_ACCESS_FAILURE is true, pass any exceptions; otherwise, return 0
        """
        try:
            return self._get(*args, **kwargs)
        except MGuiAttributeError:
            cmds.warning("Slent MGUI fail!")
            return 0
        except:
            if BREAK_ON_ACCESS_FAILURE:
                raise
            else:
                return 0


    @classmethod
    def can_access(cls, datum, fieldname):
        """
        Return true if the supplied object / fieldname combination can be accessed from this class

        Derived classes should implement this so that the AccessorFactory can
        pick the correct Accessor for a given object
        """
        return fieldname and hasattr(datum, fieldname) and not callable(getattr(datum, fieldname))

    def __nonzero__(self):
        try:
            return self.Target is not None
        except ReferenceError:<commit_msg>removed the special case error handling for attributeErrors<commit_after>"""
Created on Feb 16, 2014

@author: <NAME>
"""
import maya.cmds as cmds
from collections import Mapping
import weakref
import sys
from mGui.properties import LateBoundProperty, MGuiAttributeError
import maya.utils as utils

# these are primarily intended for debugging.
# Generally you want to break on access failure, since the Binding
# will then invalidate itself and not run again, but you don't want
# to break on bind failure, so the GUI can run without crashing
# Use this with caution, since they are effectively globals

BREAK_ON_ACCESS_FAILURE = True  # break when an accessor fails (eg, a deleted object)
BREAK_ON_BIND_FAILURE = True  # break when a binding fails (instead of silently deleting bad binding)


class BindingError(ValueError):
    pass


class Accessor(object):
    """
    An Accessor abstracts the details of getting or setting an object property,
    so that calling code can get or set values without knowing the precise
    mechanism involved.

    The base Accessor class works on plain python objects. There are derived
    classes for PyNode, maya cmds strings, dictionaries and get-set methods.

    In most cases the <Target> field is a weakref rather than a regular object
    reference. This prevents a binding from keeping an object alive in memory if
    it is not accessed anywhere else.  Some classes (such as dictionaries or datettimes)
    cannot be weak referenced so these are stored as ordinary objects.

    Truth-testing an accessor returns true if the Accessors <Target> exists.
    """

    def __init__(self, datum, fieldName):
        try:
            self.Target = weakref.proxy(datum)
        except TypeError:
            self.Target = datum
        self.FieldName = fieldName

    def _set(self, *args, **kwargs):
        setattr(self.Target, self.FieldName, args[0])

    def _get(self, *args, **kwargs):
        return getattr(self.Target, self.FieldName)

    def push(self, *args, **kwargs):
        """
        Set the value in <args> on <Target.FieldName>. Return true if the set
        was done without excepting.

        If BREAK_ON_ACCESS_FAILURE is true, pass any exceptions; otherwise they
        are silenly ignored
        """
        try:
            self._set(*args, **kwargs)
            return True
        except:
            if BREAK_ON_ACCESS_FAILURE:
                raise
            else:
                return False

    def pull(self, *args, **kwargs):
        """
        Returns the value from <Target.Fieldname>

        If BREAK_ON_ACCESS_FAILURE is true, pass any exceptions; otherwise, return 0
        """
        try:
            return self._get(*args, **kwargs)
        except:
            if BREAK_ON_ACCESS_FAILURE:
                raise
            else:
                return 0


    @classmethod
    def can_access(cls, datum, fieldname):
        """
        Return true if the supplied object / fieldname combination can be accessed from this class

        Derived classes should implement this so that the AccessorFactory can
        pick the correct Accessor for a given object
        """
        return fieldname and hasattr(datum, fieldname) and not callable(getattr(datum, fieldname))

    def __nonzero__(self):
        try:
            return self.Target is not None
        except ReferenceError:
{'fraction_non_alphanumeric': 0.061218596592549815, 'fraction_numerical': 0.0027432861680623736, 'mean_word_length': 2.54503582395087, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1950835', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1769, 'n_words': 772}