{
    "file_diffs": [
        {
            "old_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Interface information about credentials\n\nProvides minimalistic interface to deal (query, request, store) with most common\ntypes of credentials.  To be used by Authenticators\n\"\"\"\n\n__dev_doc__ = \"\"\"\nPossibly useful in the future 3rd part developments\n\nhttps://github.com/omab/python-social-auth\n    social authentication/registration mechanism with support for several\n    frameworks and auth providers\n\"\"\"\n\nimport time\nimport calendar\n\nfrom collections import OrderedDict\n\nfrom ..dochelpers import exc_str\nfrom ..support.keyring_ import keyring as keyring_\nfrom ..ui import ui\nfrom ..utils import auto_repr\nfrom ..support.network import iso8601_to_epoch\n\nfrom logging import getLogger\nlgr = getLogger('datalad.downloaders.credentials')\n\n\n@auto_repr\nclass Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.fname, f)\n\n\nclass UserPassword(Credential):\n    \"\"\"Simple type of a credential which consists of user/password pair\"\"\"\n\n    _FIELDS = OrderedDict([('user', {}),\n                           ('password', {'hidden': True})])\n\n    is_expired = False  # no expiration provisioned\n\n\nclass AWS_S3(Credential):\n    \"\"\"Credential for AWS S3 service\"\"\"\n\n    _FIELDS = OrderedDict([('key_id', {}),\n                           ('secret_id', {'hidden': True}),\n                           ('session', {'optional': True}),\n                           ('expiration', {'optional': True}),\n                           ])\n\n    @property\n    def is_expired(self):\n        exp = self.get('expiration', None)\n        if not exp:\n            return True\n        exp_epoch = iso8601_to_epoch(exp)\n        expire_in = (exp_epoch - calendar.timegm(time.localtime()))/3600.\n\n        lgr.debug(\n            (\"Credential %s has expired %.2fh ago\"\n                if expire_in <= 0 else \"Credential %s will expire in %.2fh\")\n            % (self.name, expire_in))\n        return expire_in <= 0\n\n\n@auto_repr\nclass CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()\n\n\ndef _nda_adapter(user=None, password=None):\n    from datalad.support.third.nda_aws_token_generator import NDATokenGenerator\n    gen = NDATokenGenerator()\n    token = gen.generate_token(user, password)\n    # There are also session and expiration we ignore... TODO anything about it?!!!\n    # we could create a derived AWS_S3 which would also store session and expiration\n    # and then may be Composite could use those????\n    return dict(key_id=token.access_key, secret_id=token.secret_key,\n                session=token.session, expiration=token.expiration)\n\n\nclass NDA_S3(CompositeCredential):\n    \"\"\"Credential to access NDA AWS\n\n    So for NDA we need a credential which is a composite credential.\n    User provides UserPassword and then some adapter generates AWS_S3\n    out of it\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, AWS_S3)\n    _CREDENTIAL_ADAPTERS = (_nda_adapter,)\n\n\nCREDENTIAL_TYPES = {\n    'user_password': UserPassword,\n    'aws-s3': AWS_S3,\n    'nda-s3': NDA_S3,\n}\n",
            "new_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Interface information about credentials\n\nProvides minimalistic interface to deal (query, request, store) with most common\ntypes of credentials.  To be used by Authenticators\n\"\"\"\n\n__dev_doc__ = \"\"\"\nPossibly useful in the future 3rd part developments\n\nhttps://github.com/omab/python-social-auth\n    social authentication/registration mechanism with support for several\n    frameworks and auth providers\n\"\"\"\n\nimport time\nimport calendar\n\nfrom collections import OrderedDict\n\nfrom ..dochelpers import exc_str\nfrom ..support.keyring_ import keyring as keyring_\nfrom ..ui import ui\nfrom ..utils import auto_repr\nfrom ..support.network import iso8601_to_epoch\n\nfrom logging import getLogger\nlgr = getLogger('datalad.downloaders.credentials')\n\n\n@auto_repr\nclass Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.name, f)\n\n\nclass UserPassword(Credential):\n    \"\"\"Simple type of a credential which consists of user/password pair\"\"\"\n\n    _FIELDS = OrderedDict([('user', {}),\n                           ('password', {'hidden': True})])\n\n    is_expired = False  # no expiration provisioned\n\n\nclass AWS_S3(Credential):\n    \"\"\"Credential for AWS S3 service\"\"\"\n\n    _FIELDS = OrderedDict([('key_id', {}),\n                           ('secret_id', {'hidden': True}),\n                           ('session', {'optional': True}),\n                           ('expiration', {'optional': True}),\n                           ])\n\n    @property\n    def is_expired(self):\n        exp = self.get('expiration', None)\n        if not exp:\n            return True\n        exp_epoch = iso8601_to_epoch(exp)\n        expire_in = (exp_epoch - calendar.timegm(time.localtime()))/3600.\n\n        lgr.debug(\n            (\"Credential %s has expired %.2fh ago\"\n                if expire_in <= 0 else \"Credential %s will expire in %.2fh\")\n            % (self.name, expire_in))\n        return expire_in <= 0\n\n\n@auto_repr\nclass CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(\n                C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring)\n            )\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()\n\n\ndef _nda_adapter(user=None, password=None):\n    from datalad.support.third.nda_aws_token_generator import NDATokenGenerator\n    gen = NDATokenGenerator()\n    token = gen.generate_token(user, password)\n    # There are also session and expiration we ignore... TODO anything about it?!!!\n    # we could create a derived AWS_S3 which would also store session and expiration\n    # and then may be Composite could use those????\n    return dict(key_id=token.access_key, secret_id=token.secret_key,\n                session=token.session, expiration=token.expiration)\n\n\nclass NDA_S3(CompositeCredential):\n    \"\"\"Credential to access NDA AWS\n\n    So for NDA we need a credential which is a composite credential.\n    User provides UserPassword and then some adapter generates AWS_S3\n    out of it\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, AWS_S3)\n    _CREDENTIAL_ADAPTERS = (_nda_adapter,)\n\n\nCREDENTIAL_TYPES = {\n    'user_password': UserPassword,\n    'aws-s3': AWS_S3,\n    'nda-s3': NDA_S3,\n}\n",
            "header": {
                "file": {
                    "path": "datalad/downloaders/credentials.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "715bf3eb6",
                "new_commit_hash": "54a8dd605",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/datalad/downloaders/credentials.py"
            },
            "plus_file": {
                "path": "b/datalad/downloaders/credentials.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 150,
                            "length": 7
                        },
                        "new_range": {
                            "start": 150,
                            "length": 7
                        },
                        "section": "class Credential(object):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    def delete(self):",
                                "type": "context"
                            },
                            {
                                "content": "        \"\"\"Deletes credential values from the keyring\"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "        for f in self._FIELDS:",
                                "type": "context"
                            },
                            {
                                "content": "            self._keyring.delete(self.fname, f)",
                                "type": "deleted"
                            },
                            {
                                "content": "            self._keyring.delete(self.name, f)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "class UserPassword(Credential):",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/downloaders/credentials.py",
                            "type": "method",
                            "name": "Credential.delete",
                            "content": "class Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.fname, f)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 150,
                            "end_lineno": 153,
                            "parent": {
                                "file_name": "datalad/downloaders/credentials.py",
                                "type": "class",
                                "name": "Credential",
                                "content": "class Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.fname, f)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 39,
                                "end_lineno": 153,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "datalad/downloaders/credentials.py",
                            "type": "class",
                            "name": "Credential",
                            "content": "class Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.fname, f)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 39,
                            "end_lineno": 153,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 209,
                            "length": 7
                        },
                        "new_range": {
                            "start": 209,
                            "length": 9
                        },
                        "section": "class CompositeCredential(Credential):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self._FIELDS = credentials[0]._FIELDS",
                                "type": "context"
                            },
                            {
                                "content": "        # the rest with index suffix, but storing themselves in the same keyring",
                                "type": "context"
                            },
                            {
                                "content": "        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):",
                                "type": "context"
                            },
                            {
                                "content": "            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))",
                                "type": "deleted"
                            },
                            {
                                "content": "            credentials.append(",
                                "type": "added"
                            },
                            {
                                "content": "                C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring)",
                                "type": "added"
                            },
                            {
                                "content": "            )",
                                "type": "added"
                            },
                            {
                                "content": "        self._credentials = credentials",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        super(CompositeCredential, self)._prepare()",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/downloaders/credentials.py",
                            "type": "class",
                            "name": "CompositeCredential",
                            "content": "class CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 190,
                            "end_lineno": 256,
                            "parent": null
                        },
                        {
                            "file_name": "datalad/downloaders/credentials.py",
                            "type": "method",
                            "name": "CompositeCredential._prepare",
                            "content": "class CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 198,
                            "end_lineno": 215,
                            "parent": {
                                "file_name": "datalad/downloaders/credentials.py",
                                "type": "class",
                                "name": "CompositeCredential",
                                "content": "class CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 190,
                                "end_lineno": 256,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Tests for credentials\"\"\"\n\nfrom datalad.tests.utils import with_testsui\nfrom datalad.tests.utils import assert_equal\nfrom datalad.tests.utils import assert_true, assert_false\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import SkipTest\nfrom datalad.support.keyring_ import MemoryKeyring\nfrom ..credentials import UserPassword\n\n\n@with_testsui(responses=['user1', 'password1'])\ndef test_cred1_enter_new():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    assert_false(cred.is_known)\n    assert_equal(cred.enter_new(), None)\n    assert_true(cred.is_known)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    keyring.delete('name')\n    assert_raises(KeyError, keyring.delete, 'name', 'user')\n    assert_raises(KeyError, keyring.delete, 'name')\n    assert_equal(keyring.get('name', 'user'), None)\n\n\n@with_testsui(responses=['password1'])\ndef test_cred1_call():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    # we will set the name but not the password, expecting UI\n    # requesting it\n    assert_equal(keyring.set('name', 'user', 'user1'), None)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(cred(), {'user': 'user1', 'password': 'password1'})\n    assert_equal(keyring.get('name', 'password'), 'password1')\n\n\ndef test_keyring():\n    # mock out keyring methods and test that we are providing correct values\n    # with 'datalad-' prefix\n    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")",
            "new_file_content": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Tests for credentials\"\"\"\n\nfrom datalad.tests.utils import with_testsui\nfrom datalad.tests.utils import assert_equal\nfrom datalad.tests.utils import assert_true, assert_false\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import SkipTest\nfrom datalad.support.keyring_ import MemoryKeyring\nfrom ..credentials import UserPassword\nfrom ..credentials import CompositeCredential\n\n\n@with_testsui(responses=['user1', 'password1'])\ndef test_cred1_enter_new():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    assert_false(cred.is_known)\n    assert_equal(cred.enter_new(), None)\n    assert_true(cred.is_known)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    keyring.delete('name')\n    assert_raises(KeyError, keyring.delete, 'name', 'user')\n    assert_raises(KeyError, keyring.delete, 'name')\n    assert_equal(keyring.get('name', 'user'), None)\n\n\n@with_testsui(responses=['password1'])\ndef test_cred1_call():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    # we will set the name but not the password, expecting UI\n    # requesting it\n    assert_equal(keyring.set('name', 'user', 'user1'), None)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(cred(), {'user': 'user1', 'password': 'password1'})\n    assert_equal(keyring.get('name', 'password'), 'password1')\n\n\ndef test_keyring():\n    # mock out keyring methods and test that we are providing correct values\n    # with 'datalad-' prefix\n    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")\n\n\ndef _cred1_adapter(user=None, password=None):\n    \"\"\"Just a sample adapter from one user/pw type to another\"\"\"\n    return dict(user=user + \"_1\", password=password + \"_2\")\n\n\nclass _CCred1(CompositeCredential):\n    \"\"\"A Simple composite credential which will do some entries transformation\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, UserPassword)\n    _CREDENTIAL_ADAPTERS = (_cred1_adapter,)\n\n\n@with_testsui(responses=['user1', 'password1',\n                         'user2', 'password2'])\ndef test_composite_credential1():\n    # basic test of composite credential\n    keyring = MemoryKeyring()\n    cred = _CCred1(\"name\", keyring=keyring)\n    assert_equal(cred(), {'user': 'user1_1', 'password': 'password1_2'})\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    # ATM composite credential stores \"derived\" ones unconditionally in the\n    # keyring as well\n    assert_equal(keyring.get('name:1', 'user'), 'user1_1')\n    assert_equal(keyring.get('name:1', 'password'), 'password1_2')\n\n    # and now enter new should remove \"derived\" entries\n    cred.enter_new()\n    assert_equal(keyring.get('name', 'user'), 'user2')\n    assert_equal(keyring.get('name', 'password'), 'password2')\n    assert_equal(keyring.get('name:1', 'user'), None)\n    assert_equal(keyring.get('name:1', 'password'), None)\n    # which would get reevaluated if requested\n    assert_equal(keyring.entries, {('name', 'user'): 'user2', ('name', 'password'): 'password2'})\n    assert_equal(cred(), {'user': 'user2_1', 'password': 'password2_2'})\n",
            "header": {
                "file": {
                    "path": "datalad/downloaders/tests/test_credentials.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "16c5a569b",
                "new_commit_hash": "6221bd363",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/datalad/downloaders/tests/test_credentials.py"
            },
            "plus_file": {
                "path": "b/datalad/downloaders/tests/test_credentials.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 15,
                            "length": 6
                        },
                        "new_range": {
                            "start": 15,
                            "length": 7
                        },
                        "section": "from datalad.tests.utils import assert_raises"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "from datalad.tests.utils import SkipTest",
                                "type": "context"
                            },
                            {
                                "content": "from datalad.support.keyring_ import MemoryKeyring",
                                "type": "context"
                            },
                            {
                                "content": "from ..credentials import UserPassword",
                                "type": "context"
                            },
                            {
                                "content": "from ..credentials import CompositeCredential",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "@with_testsui(responses=['user1', 'password1'])",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "datalad/downloaders/tests/test_credentials.py",
                            "type": "statement",
                            "name": "",
                            "content": "from ..credentials import CompositeCredential",
                            "ast_type_str": "ImportFrom",
                            "start_lineno": 18,
                            "end_lineno": 18,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 47,
                            "length": 4
                        },
                        "new_range": {
                            "start": 48,
                            "length": 41
                        },
                        "section": "def test_cred1_call():"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "def test_keyring():",
                                "type": "context"
                            },
                            {
                                "content": "    # mock out keyring methods and test that we are providing correct values",
                                "type": "context"
                            },
                            {
                                "content": "    # with 'datalad-' prefix",
                                "type": "context"
                            },
                            {
                                "content": "    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")",
                                "type": "deleted"
                            },
                            {
                                "content": "No newline at end of file",
                                "type": "note"
                            },
                            {
                                "content": "    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "def _cred1_adapter(user=None, password=None):",
                                "type": "added"
                            },
                            {
                                "content": "    \"\"\"Just a sample adapter from one user/pw type to another\"\"\"",
                                "type": "added"
                            },
                            {
                                "content": "    return dict(user=user + \"_1\", password=password + \"_2\")",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "class _CCred1(CompositeCredential):",
                                "type": "added"
                            },
                            {
                                "content": "    \"\"\"A Simple composite credential which will do some entries transformation",
                                "type": "added"
                            },
                            {
                                "content": "    \"\"\"",
                                "type": "added"
                            },
                            {
                                "content": "    _CREDENTIAL_CLASSES = (UserPassword, UserPassword)",
                                "type": "added"
                            },
                            {
                                "content": "    _CREDENTIAL_ADAPTERS = (_cred1_adapter,)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "@with_testsui(responses=['user1', 'password1',",
                                "type": "added"
                            },
                            {
                                "content": "                         'user2', 'password2'])",
                                "type": "added"
                            },
                            {
                                "content": "def test_composite_credential1():",
                                "type": "added"
                            },
                            {
                                "content": "    # basic test of composite credential",
                                "type": "added"
                            },
                            {
                                "content": "    keyring = MemoryKeyring()",
                                "type": "added"
                            },
                            {
                                "content": "    cred = _CCred1(\"name\", keyring=keyring)",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cred(), {'user': 'user1_1', 'password': 'password1_2'})",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name', 'user'), 'user1')",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name', 'password'), 'password1')",
                                "type": "added"
                            },
                            {
                                "content": "    # ATM composite credential stores \"derived\" ones unconditionally in the",
                                "type": "added"
                            },
                            {
                                "content": "    # keyring as well",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name:1', 'user'), 'user1_1')",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name:1', 'password'), 'password1_2')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    # and now enter new should remove \"derived\" entries",
                                "type": "added"
                            },
                            {
                                "content": "    cred.enter_new()",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name', 'user'), 'user2')",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name', 'password'), 'password2')",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name:1', 'user'), None)",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.get('name:1', 'password'), None)",
                                "type": "added"
                            },
                            {
                                "content": "    # which would get reevaluated if requested",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(keyring.entries, {('name', 'user'): 'user2', ('name', 'password'): 'password2'})",
                                "type": "added"
                            },
                            {
                                "content": "    assert_equal(cred(), {'user': 'user2_1', 'password': 'password2_2'})",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "datalad/downloaders/tests/test_credentials.py",
                            "type": "function",
                            "name": "test_keyring",
                            "content": "def test_keyring():\n    # mock out keyring methods and test that we are providing correct values\n    # with 'datalad-' prefix\n    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 47,
                            "end_lineno": 50,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "datalad/downloaders/tests/test_credentials.py",
                            "type": "function",
                            "name": "_cred1_adapter",
                            "content": "def _cred1_adapter(user=None, password=None):\n    \"\"\"Just a sample adapter from one user/pw type to another\"\"\"\n    return dict(user=user + \"_1\", password=password + \"_2\")",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 54,
                            "end_lineno": 56,
                            "parent": null
                        },
                        {
                            "file_name": "datalad/downloaders/tests/test_credentials.py",
                            "type": "function",
                            "name": "test_composite_credential1",
                            "content": "def test_composite_credential1():\n    # basic test of composite credential\n    keyring = MemoryKeyring()\n    cred = _CCred1(\"name\", keyring=keyring)\n    assert_equal(cred(), {'user': 'user1_1', 'password': 'password1_2'})\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    # ATM composite credential stores \"derived\" ones unconditionally in the\n    # keyring as well\n    assert_equal(keyring.get('name:1', 'user'), 'user1_1')\n    assert_equal(keyring.get('name:1', 'password'), 'password1_2')\n\n    # and now enter new should remove \"derived\" entries\n    cred.enter_new()\n    assert_equal(keyring.get('name', 'user'), 'user2')\n    assert_equal(keyring.get('name', 'password'), 'password2')\n    assert_equal(keyring.get('name:1', 'user'), None)\n    assert_equal(keyring.get('name:1', 'password'), None)\n    # which would get reevaluated if requested\n    assert_equal(keyring.entries, {('name', 'user'): 'user2', ('name', 'password'): 'password2'})\n    assert_equal(cred(), {'user': 'user2_1', 'password': 'password2_2'})",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 68,
                            "end_lineno": 88,
                            "parent": null
                        },
                        {
                            "file_name": "datalad/downloaders/tests/test_credentials.py",
                            "type": "class",
                            "name": "_CCred1",
                            "content": "class _CCred1(CompositeCredential):\n    \"\"\"A Simple composite credential which will do some entries transformation\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, UserPassword)\n    _CREDENTIAL_ADAPTERS = (_cred1_adapter,)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 59,
                            "end_lineno": 63,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "f60aa45148b4e40a6954871e7d0cfd579721f0c8^",
    "new_commit_hash": "f60aa45148b4e40a6954871e7d0cfd579721f0c8",
    "commit_message": "ENH(TST)+BF: basic test for CompositeCredential and a bugfix for a triggered bug",
    "commit_date": "2016-07-05T17:34:58-04:00",
    "metadata": {}
}
{
    "repo_name": "datalad",
    "new_commit_hash": "f60aa45148b4e40a6954871e7d0cfd579721f0c8",
    "test_file_codes": [
        "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Tests for credentials\"\"\"\n\nfrom datalad.tests.utils import with_testsui\nfrom datalad.tests.utils import assert_equal\nfrom datalad.tests.utils import assert_true, assert_false\nfrom datalad.tests.utils import assert_raises\nfrom datalad.tests.utils import SkipTest\nfrom datalad.support.keyring_ import MemoryKeyring\nfrom datalad.downloaders.credentials import UserPassword\nfrom datalad.downloaders.credentials import CompositeCredential\n\n\n@with_testsui(responses=['user1', 'password1'])\ndef test_cred1_enter_new():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    assert_false(cred.is_known)\n    assert_equal(cred.enter_new(), None)\n    assert_true(cred.is_known)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    keyring.delete('name')\n    assert_raises(KeyError, keyring.delete, 'name', 'user')\n    assert_raises(KeyError, keyring.delete, 'name')\n    assert_equal(keyring.get('name', 'user'), None)\n\n\n@with_testsui(responses=['password1'])\ndef test_cred1_call():\n    keyring = MemoryKeyring()\n    cred = UserPassword(\"name\", keyring=keyring)\n    # we will set the name but not the password, expecting UI\n    # requesting it\n    assert_equal(keyring.set('name', 'user', 'user1'), None)\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(cred(), {'user': 'user1', 'password': 'password1'})\n    assert_equal(keyring.get('name', 'password'), 'password1')\n\n\ndef test_keyring():\n    # mock out keyring methods and test that we are providing correct values\n    # with 'datalad-' prefix\n    raise SkipTest(\"provide tests for Keyring which interfaces keyring module\")\n\n\ndef _cred1_adapter(user=None, password=None):\n    \"\"\"Just a sample adapter from one user/pw type to another\"\"\"\n    return dict(user=user + \"_1\", password=password + \"_2\")\n\n\nclass _CCred1(CompositeCredential):\n    \"\"\"A Simple composite credential which will do some entries transformation\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, UserPassword)\n    _CREDENTIAL_ADAPTERS = (_cred1_adapter,)\n\n\n@with_testsui(responses=['user1', 'password1',\n                         'user2', 'password2'])\ndef test_composite_credential1():\n    # basic test of composite credential\n    keyring = MemoryKeyring()\n    cred = _CCred1(\"name\", keyring=keyring)\n    assert_equal(cred(), {'user': 'user1_1', 'password': 'password1_2'})\n    assert_equal(keyring.get('name', 'user'), 'user1')\n    assert_equal(keyring.get('name', 'password'), 'password1')\n    # ATM composite credential stores \"derived\" ones unconditionally in the\n    # keyring as well\n    assert_equal(keyring.get('name:1', 'user'), 'user1_1')\n    assert_equal(keyring.get('name:1', 'password'), 'password1_2')\n\n    # and now enter new should remove \"derived\" entries\n    cred.enter_new()\n    assert_equal(keyring.get('name', 'user'), 'user2')\n    assert_equal(keyring.get('name', 'password'), 'password2')\n    assert_equal(keyring.get('name:1', 'user'), None)\n    assert_equal(keyring.get('name:1', 'password'), None)\n    # which would get reevaluated if requested\n    assert_equal(keyring.entries, {('name', 'user'): 'user2', ('name', 'password'): 'password2'})\n    assert_equal(cred(), {'user': 'user2_1', 'password': 'password2_2'})\n",
        "import pytest\nimport tempfile\nimport os\n\n\n@pytest.fixture\ndef path():\n    with tempfile.TemporaryDirectory() as tmpdir:\n        yield tmpdir\n\n\n@pytest.fixture(autouse=True)\ndef setup_git_config():\n    with tempfile.TemporaryDirectory() as home:\n        old_home = os.environ.get(\"HOME\")\n        os.environ[\"HOME\"] = home\n        os.system('git config --global user.name \"DataLad Tester\"')\n        os.system('git config --global user.email \"test@example.com\"')\n        yield\n        if old_home:\n            os.environ[\"HOME\"] = old_home\n"
    ],
    "test_file_names": [
        "test_1.py",
        "conftest.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Datalad installation attempts...\nVerifying installation...\n❌ Verification failed\nPython 3.9 installation failed, trying Python 3.7...\nVerifying installation...\nDatalad version: 0.2.3.dev61\n✅ Installation successful!\nSuccessfully installed Datalad using Python 3.7\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 25 packages in 16ms\nInstalled 25 packages in 5.60s\n + coverage==7.6.10\n + docopt==0.6.2\n + exceptiongroup==1.2.2\n + grabbit==0.2.6\n + importlib-resources==6.4.5\n + iniconfig==2.0.0\n + nibabel==5.3.2\n + num2words==0.5.14\n + numpy==2.0.2\n + packaging==24.2\n + pandas==2.2.3\n + patsy==1.0.1\n + pluggy==1.5.0\n + pybids==0.6.5\n + pytest==8.3.4\n + pytest-cov==6.0.0\n + python-dateutil==2.9.0.post0\n + pytz==2024.2\n + scipy==1.13.1\n + setuptools==75.6.0\n + six==1.17.0\n + tomli==2.2.1\n + typing-extensions==4.12.2\n + tzdata==2024.2\n + zipp==3.21.0\nerror: The build backend returned an error\n  Caused by: Call to `setuptools.build_meta:__legacy__.build_editable` failed (exit status: 1)\n\n[stderr]\nTraceback (most recent call last):\n  File \"<string>\", line 14, in <module>\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpxGOEDR/lib/python3.9/site-packages/setuptools/build_meta.py\", line 483, in get_requires_for_build_editable\n    return self.get_requires_for_build_wheel(config_settings)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpxGOEDR/lib/python3.9/site-packages/setuptools/build_meta.py\", line 334, in get_requires_for_build_wheel\n    return self._get_build_requires(config_settings, requirements=[])\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpxGOEDR/lib/python3.9/site-packages/setuptools/build_meta.py\", line 304, in _get_build_requires\n    self.run_setup()\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpxGOEDR/lib/python3.9/site-packages/setuptools/build_meta.py\", line 522, in run_setup\n    super().run_setup(setup_script=setup_script)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmpxGOEDR/lib/python3.9/site-packages/setuptools/build_meta.py\", line 320, in run_setup\n    exec(code, locals())\n  File \"<string>\", line 39, in <module>\nAttributeError: module 'platform' has no attribute 'dist'\n\nhint: This usually indicates a problem with the package or the build environment.\nerror: The build backend returned an error\n  Caused by: Call to `setuptools.build_meta:__legacy__.build_editable` failed (exit status: 1)\n\n[stderr]\nTraceback (most recent call last):\n  File \"<string>\", line 14, in <module>\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmphw3RxS/lib/python3.9/site-packages/setuptools/build_meta.py\", line 483, in get_requires_for_build_editable\n    return self.get_requires_for_build_wheel(config_settings)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmphw3RxS/lib/python3.9/site-packages/setuptools/build_meta.py\", line 334, in get_requires_for_build_wheel\n    return self._get_build_requires(config_settings, requirements=[])\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmphw3RxS/lib/python3.9/site-packages/setuptools/build_meta.py\", line 304, in _get_build_requires\n    self.run_setup()\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmphw3RxS/lib/python3.9/site-packages/setuptools/build_meta.py\", line 522, in run_setup\n    super().run_setup(setup_script=setup_script)\n  File \"/home/gcpuser/.cache/uv/builds-v0/.tmphw3RxS/lib/python3.9/site-packages/setuptools/build_meta.py\", line 320, in run_setup\n    exec(code, locals())\n  File \"<string>\", line 39, in <module>\nAttributeError: module 'platform' has no attribute 'dist'\n\nhint: This usually indicates a problem with the package or the build environment.\nTraceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8/datalad/__init__.py\", line 20, in <module>\n    from .config import ConfigManager\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8/datalad/config.py\", line 17, in <module>\n    from appdirs import AppDirs\nModuleNotFoundError: No module named 'appdirs'\nUsing CPython 3.7.9\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 26 packages in 300ms\nInstalled 26 packages in 2.50s\n + bids==0.0\n + coverage==7.2.7\n + docopt==0.6.2\n + exceptiongroup==1.2.2\n + fasteners==0.19\n + grabbit==0.2.6\n + importlib-metadata==6.7.0\n + iniconfig==2.0.0\n + nibabel==4.0.2\n + num2words==0.5.14\n + numpy==1.21.6\n + packaging==24.0\n + pandas==1.3.5\n + patsy==1.0.1\n + pluggy==1.2.0\n + pybids==0.6.5\n + pytest==7.4.4\n + pytest-cov==4.1.0\n + python-dateutil==2.9.0.post0\n + pytz==2024.2\n + scipy==1.7.3\n + setuptools==68.0.0\n + six==1.17.0\n + tomli==2.0.1\n + typing-extensions==4.7.1\n + zipp==3.15.0\nResolved 68 packages in 3.69s\nPrepared 1 package in 3.72s\nInstalled 62 packages in 180ms\n + appdirs==1.4.4\n + attrs==24.2.0\n + automat==22.10.0\n + beautifulsoup4==4.12.3\n + boto==2.49.0\n + certifi==2024.12.14\n + cffi==1.15.1\n + charset-normalizer==3.4.1\n + constantly==15.1.0\n + cryptography==44.0.0\n + cssselect==1.2.0\n + datalad==0.2.3 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8)\n + filelock==3.12.2\n + gitdb==4.0.12\n + gitpython==3.1.44\n + httpretty==1.1.4\n + humanize==4.6.0\n + hyperlink==21.0.0\n + idna==3.10\n + importlib-resources==5.12.0\n + incremental==22.10.0\n + iso8601==2.1.0\n + itemadapter==0.8.0\n + itemloaders==1.1.0\n + jaraco-classes==3.2.3\n + jeepney==0.8.0\n + jmespath==1.0.1\n + keyring==24.1.1\n + keyrings-alt==4.2.0\n + lxml==5.3.0\n + mock==5.1.0\n + more-itertools==9.1.0\n + msgpack-python==0.5.6\n + multidict==6.0.5\n + nose==1.3.7\n + parsel==1.8.1\n + patool==1.12\n + protego==0.3.0\n + pyasn1==0.5.1\n + pyasn1-modules==0.3.0\n + pycparser==2.21\n + pydispatcher==2.0.7\n + pyopenssl==24.3.0\n + pyyaml==6.0.1\n + queuelib==1.6.2\n + requests==2.31.0\n + requests-file==2.1.0\n + scrapy==2.9.0\n + secretstorage==3.3.3\n + service-identity==21.1.0\n + smmap==5.0.2\n + soupsieve==2.4.1\n + testtools==2.7.1\n + tldextract==4.0.0\n + tqdm==4.67.1\n + twisted==23.8.0\n + urllib3==2.0.7\n + vcrpy==4.3.0\n + w3lib==2.1.2\n + wrapt==1.16.0\n + yarl==1.9.4\n + zope-interface==6.4.post2\nAudited 1 package in 52ms\n/home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8/.venv/lib/python3.7/site-packages/urllib3/__init__.py:38: NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 3.1.4'. See: https://github.com/urllib3/urllib3/issues/3020\n  exceptions.NotOpenSSLWarning,\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8\nplugins: cov-4.1.0\ncollected 4 items\n\nr2e_tests/test_1.py ..s.                                                 [100%]\n\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_cred1_enter_new\nPASSED r2e_tests/test_1.py::test_cred1_call\nPASSED r2e_tests/test_1.py::test_composite_credential1\nSKIPPED [1] .venv/lib/python3.7/site-packages/_pytest/unittest.py:371: provide tests for Keyring which interfaces keyring module\n========================= 3 passed, 1 skipped in 1.35s =========================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/datalad_f60aa45148b4e40a6954871e7d0cfd579721f0c8\nplugins: cov-4.1.0\ncollected 4 items\n\nr2e_tests/test_1.py ..sF                                                 [100%]\n\n=================================== FAILURES ===================================\n__________________________ test_composite_credential1 __________________________\n\n    @with_testsui(responses=['user1', 'password1',\n                             'user2', 'password2'])\n    def test_composite_credential1():\n        # basic test of composite credential\n        keyring = MemoryKeyring()\n        cred = _CCred1(\"name\", keyring=keyring)\n        assert_equal(cred(), {'user': 'user1_1', 'password': 'password1_2'})\n        assert_equal(keyring.get('name', 'user'), 'user1')\n        assert_equal(keyring.get('name', 'password'), 'password1')\n        # ATM composite credential stores \"derived\" ones unconditionally in the\n        # keyring as well\n        assert_equal(keyring.get('name:1', 'user'), 'user1_1')\n        assert_equal(keyring.get('name:1', 'password'), 'password1_2')\n    \n        # and now enter new should remove \"derived\" entries\n>       cred.enter_new()\n\nr2e_tests/test_1.py:81: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ndatalad/downloaders/credentials.py:226: in enter_new\n    c.delete()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = UserPassword(name='name:1', url=None)\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n>           self._keyring.delete(self.fname, f)\nE           AttributeError: 'UserPassword' object has no attribute 'fname'\n\ndatalad/downloaders/credentials.py:153: AttributeError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_cred1_enter_new\nPASSED r2e_tests/test_1.py::test_cred1_call\nSKIPPED [1] .venv/lib/python3.7/site-packages/_pytest/unittest.py:371: provide tests for Keyring which interfaces keyring module\nFAILED r2e_tests/test_1.py::test_composite_credential1 - AttributeError: 'Use...\n==================== 1 failed, 2 passed, 1 skipped in 0.55s ====================\n",
    "old_commit_res_stderr": ""
}
datalad/downloaders/credentials.py datalad/downloaders/tests/test_credentials.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** AttributeError: 'UserPassword' object has no attribute 'fname' when deleting credentials

**Description:**
When attempting to delete a composite credential, an `AttributeError` is raised because the `UserPassword` object does not have a `fname` attribute. This prevents the credentials from being properly removed from the keyring.

**Example Code:**
```python
from datalad.downloaders.credentials import CompositeCredential, MemoryKeyring

keyring = MemoryKeyring()
cred = CompositeCredential("name", keyring=keyring)
cred.enter_new()
cred.delete()  # This line triggers the AttributeError
```

**Expected Behavior:**
The `delete` method should successfully remove all credential values associated with the given name from the keyring without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'UserPassword' object has no attribute 'fname'
```

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### datalad/downloaders/credentials.py
# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
# ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the datalad package for the
#   copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Interface information about credentials

Provides minimalistic interface to deal (query, request, store) with most common
types of credentials.  To be used by Authenticators
"""

__dev_doc__ = """
Possibly useful in the future 3rd part developments

https://github.com/omab/python-social-auth
    social authentication/registration mechanism with support for several
    frameworks and auth providers
"""

import time
import calendar

from collections import OrderedDict

from ..dochelpers import exc_str
from ..support.keyring_ import keyring as keyring_
from ..ui import ui
from ..utils import auto_repr
from ..support.network import iso8601_to_epoch

from logging import getLogger
lgr = getLogger('datalad.downloaders.credentials')


@auto_repr
class Credential(object):
    """Base class for different types of credentials
    """

    # Should be defined in a subclass as an OrderedDict of fields
    # name -> dict(attributes)
    _FIELDS = None
    _KNOWN_ATTRS = {
        'hidden',    # UI should not display the value
        'optional',  # Not mandatory thus not requested if not set
    }

    def __init__(self, name, url=None, keyring=None):
        """
        Parameters
        ----------
        name : str
            Name of the credential, as it would be identified by in the centralized
            storage of credentials
        url : str, optional
            URL string to point users to where to seek obtaining the credentials
        keyring : a keyring
            An object providing (g|s)et_password.  If None, keyring module is used
            as is
        """
        self.name = name
        self.url = url
        self._keyring = keyring or keyring_
        self._prepare()

    def _prepare(self):
        """Additional house-keeping possibly to be performed in subclasses

        Created to avoid all the passing args/kwargs of __init__ all the time
        """
        # Basic checks
        for f, fattrs in self._FIELDS.items():
            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)
            if unknown_attrs:
                raise ValueError("Unknown attributes %s. Known are: %s"
                                 % (unknown_attrs, self._KNOWN_ATTRS))

    def _is_field_optional(self, f):
        return self._FIELDS[f].get('optional', False)

    def _is_field_hidden(self, f):
        return self._FIELDS[f].get('hidden', False)

    @property
    def is_known(self):
        """Return True if values for all fields of the credential are known"""
        try:
            return all(
                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None
                for f in self._FIELDS)
        except Exception as exc:
            lgr.warning("Failed to query keyring: %s" % exc_str(exc))
            return False

    def _ask_field_value(self, f):
        return ui.question(
            f,
            title="You need to authenticate with %r credentials." % self.name +
                  " %s provides information on how to gain access"
                  % self.url if self.url else '',
            hidden=self._is_field_hidden(f))

    def _ask_and_set(self, f):
        v = self._ask_field_value(f)
        self.set(**{f: v})
        return v

    def enter_new(self):
        """Enter new values for the credential fields"""
        # Use ui., request credential fields corresponding to the type
        for f in self._FIELDS:
            if not self._is_field_optional(f):
                self._ask_and_set(f)

    def __call__(self):
        """Obtain credentials from a keyring and if any is not known -- ask"""
        name = self.name
        fields = {}
        for f in self._FIELDS:
            v = self._keyring.get(name, f)
            if not self._is_field_optional(f):
                while v is None:  # was not known
                    v = self._ask_and_set(f)
                fields[f] = v
            elif v is not None:
                fields[f] = v
        return fields

    def set(self, **kwargs):
        """Set field(s) of the credential"""
        for f, v in kwargs.items():
            if f not in self._FIELDS:
                raise ValueError("Unknown field %s. Known are: %s"
                                 % (f, self._FIELDS.keys()))
            self._keyring.set(self.name, f, v)

    def get(self, f, default=None):
        """Get a field of the credential"""
        if f not in self._FIELDS:
            raise ValueError("Unknown field %s. Known are: %s"
                             % (f, self._FIELDS.keys()))
        try:
            return self._keyring.get(self.name, f)
        except:
            return default

    def delete(self):
        """Deletes credential values from the keyring"""
        for f in self._FIELDS:
            self._keyring.delete(self.fname, f)


class UserPassword(Credential):
    """Simple type of a credential which consists of user/password pair"""

    _FIELDS = OrderedDict([('user', {}),
                           ('password', {'hidden': True})])

    is_expired = False  # no expiration provisioned


class AWS_S3(Credential):
    """Credential for AWS S3 service"""

    _FIELDS = OrderedDict([('key_id', {}),
                           ('secret_id', {'hidden': True}),
                           ('session', {'optional': True}),
                           ('expiration', {'optional': True}),
                           ])

    @property
    def is_expired(self):
        exp = self.get('expiration', None)
        if not exp:
            return True
        exp_epoch = iso8601_to_epoch(exp)
        expire_in = (exp_epoch - calendar.timegm(time.localtime()))/3600.

        lgr.debug(
            ("Credential %s has expired %.2fh ago"
                if expire_in <= 0 else "Credential %s will expire in %.2fh")
            % (self.name, expire_in))
        return expire_in <= 0


@auto_repr
class CompositeCredential(Credential):
    """Credential which represent a sequence of Credentials where front one is exposed to user
    """

    # To be defined in sub-classes
    _CREDENTIAL_CLASSES = None
    _CREDENTIAL_ADAPTERS = None

    def _prepare(self):
        assert len(self._CREDENTIAL_CLASSES) > 1, "makes sense only if there is > 1 credential"
        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \
            "there should be 1 less of adapter than _CREDENTIAL_CLASSES"

        for C in self._CREDENTIAL_CLASSES:
            assert issubclass(C, Credential), "%s must be a subclass of Credential" % C

        # First credential should bear the name and url
        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]
        # and we just reuse its _FIELDS for _ask_field_value etc
        self._FIELDS = credentials[0]._FIELDS
        # the rest with index suffix, but storing themselves in the same keyring
        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):
            credentials.append(C(name="%s:%d" % (self.name, iC+1), url=None, keyring=self._keyring))
        self._credentials = credentials

        super(CompositeCredential, self)._prepare()

    # Here it becomes tricky, since theoretically it is the "tail"
    # ones which might expire etc, so we wouldn't exactly know what
    # new credentials outside process wanted -- it would be silly to ask
    # right away the "entry" credentials if it is just the expiration of the
    # tail credentials
    def enter_new(self):
        # should invalidate/remove all tail credentials to avoid failing attempts to login
        self._credentials[0].enter_new()
        for c in self._credentials[1:]:
            c.delete()

    def __call__(self):
        """Obtain credentials from a keyring and if any is not known -- ask"""
        name = self.name

        # Start from the tail until we have credentials set
        idx = len(self._credentials) - 1
        for c in self._credentials[::-1]:
            if c.is_known and not c.is_expired:
                break
            idx -= 1

        if idx < 0:
            # none was known, all the same -- start with the first one
            idx = 0

        # TODO: consider moving logic of traversal into authenticator since it is
        # the one spitting out authentication error etc
        # Theoretically we could just reuse 'fields' from adapter in the next step
        # but let's do full circle, so that if any "normalization" is done by
        # Credentials we take that into account
        for c, adapter, next_c in zip(
                self._credentials[idx:],
                self._CREDENTIAL_ADAPTERS[idx:],
                self._credentials[idx+1:]):
            fields = c()
            next_fields = adapter(**fields)
            next_c.set(**next_fields)

        return self._credentials[-1]()


def _nda_adapter(user=None, password=None):
    from datalad.support.third.nda_aws_token_generator import NDATokenGenerator
    gen = NDATokenGenerator()
    token = gen.generate_token(user, password)
    # There are also session and expiration we ignore... TODO anything about it?!!!
    # we could create a derived AWS_S3 which would also store session and expiration
    # and then may be Composite could use those????
    return dict(key_id=token.access_key, secret_id=token.secret_key,
                session=token.session, expiration=token.expiration)


class NDA_S3(CompositeCredential):
    """Credential to access NDA AWS

    So for NDA we need a credential which is a composite credential.
    User provides UserPassword and then some adapter generates AWS_S3
    out of it
    """
    _CREDENTIAL_CLASSES = (UserPassword, AWS_S3)
    _CREDENTIAL_ADAPTERS = (_nda_adapter,)


CREDENTIAL_TYPES = {
    'user_password': UserPassword,
    'aws-s3': AWS_S3,
    'nda-s3': NDA_S3,
}

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** AttributeError: 'UserPassword' object has no attribute 'fname' when deleting credentials

**Description:**
When attempting to delete a composite credential, an `AttributeError` is raised because the `UserPassword` object does not have a `fname` attribute. This prevents the credentials from being properly removed from the keyring.

**Example Code:**
```python
from datalad.downloaders.credentials import CompositeCredential, MemoryKeyring

keyring = MemoryKeyring()
cred = CompositeCredential("name", keyring=keyring)
cred.enter_new()
cred.delete()  # This line triggers the AttributeError
```

**Expected Behavior:**
The `delete` method should successfully remove all credential values associated with the given name from the keyring without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'UserPassword' object has no attribute 'fname'
```

[/ISSUE]
{
    "test_cred1_enter_new": "PASSED",
    "test_cred1_call": "PASSED",
    "test_composite_credential1": "PASSED"
}
diff --git a/datalad/downloaders/credentials.py b/datalad/downloaders/credentials.py
index 715bf3eb6..54a8dd605 100644
--- a/datalad/downloaders/credentials.py
+++ b/datalad/downloaders/credentials.py
@@ -150,7 +150,7 @@ class Credential(object):
     def delete(self):
         """Deletes credential values from the keyring"""
         for f in self._FIELDS:
-            self._keyring.delete(self.fname, f)
+            self._keyring.delete(self.name, f)
 
 
 class UserPassword(Credential):
@@ -209,7 +209,9 @@ class CompositeCredential(Credential):
         self._FIELDS = credentials[0]._FIELDS
         # the rest with index suffix, but storing themselves in the same keyring
         for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):
-            credentials.append(C(name="%s:%d" % (self.name, iC+1), url=None, keyring=self._keyring))
+            credentials.append(
+                C(name="%s:%d" % (self.name, iC+1), url=None, keyring=self._keyring)
+            )
         self._credentials = credentials
 
         super(CompositeCredential, self)._prepare()

{"datalad/downloaders/credentials.py": "# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-\n# ex: set sts=4 ts=4 sw=4 noet:\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n#\n#   See COPYING file distributed along with the datalad package for the\n#   copyright and license terms.\n#\n# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n\"\"\"Interface information about credentials\n\nProvides minimalistic interface to deal (query, request, store) with most common\ntypes of credentials.  To be used by Authenticators\n\"\"\"\n\n__dev_doc__ = \"\"\"\nPossibly useful in the future 3rd part developments\n\nhttps://github.com/omab/python-social-auth\n    social authentication/registration mechanism with support for several\n    frameworks and auth providers\n\"\"\"\n\nimport time\nimport calendar\n\nfrom collections import OrderedDict\n\nfrom ..dochelpers import exc_str\nfrom ..support.keyring_ import keyring as keyring_\nfrom ..ui import ui\nfrom ..utils import auto_repr\nfrom ..support.network import iso8601_to_epoch\n\nfrom logging import getLogger\nlgr = getLogger('datalad.downloaders.credentials')\n\n\n@auto_repr\nclass Credential(object):\n    \"\"\"Base class for different types of credentials\n    \"\"\"\n\n    # Should be defined in a subclass as an OrderedDict of fields\n    # name -> dict(attributes)\n    _FIELDS = None\n    _KNOWN_ATTRS = {\n        'hidden',    # UI should not display the value\n        'optional',  # Not mandatory thus not requested if not set\n    }\n\n    def __init__(self, name, url=None, keyring=None):\n        \"\"\"\n        Parameters\n        ----------\n        name : str\n            Name of the credential, as it would be identified by in the centralized\n            storage of credentials\n        url : str, optional\n            URL string to point users to where to seek obtaining the credentials\n        keyring : a keyring\n            An object providing (g|s)et_password.  If None, keyring module is used\n            as is\n        \"\"\"\n        self.name = name\n        self.url = url\n        self._keyring = keyring or keyring_\n        self._prepare()\n\n    def _prepare(self):\n        \"\"\"Additional house-keeping possibly to be performed in subclasses\n\n        Created to avoid all the passing args/kwargs of __init__ all the time\n        \"\"\"\n        # Basic checks\n        for f, fattrs in self._FIELDS.items():\n            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)\n            if unknown_attrs:\n                raise ValueError(\"Unknown attributes %s. Known are: %s\"\n                                 % (unknown_attrs, self._KNOWN_ATTRS))\n\n    def _is_field_optional(self, f):\n        return self._FIELDS[f].get('optional', False)\n\n    def _is_field_hidden(self, f):\n        return self._FIELDS[f].get('hidden', False)\n\n    @property\n    def is_known(self):\n        \"\"\"Return True if values for all fields of the credential are known\"\"\"\n        try:\n            return all(\n                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None\n                for f in self._FIELDS)\n        except Exception as exc:\n            lgr.warning(\"Failed to query keyring: %s\" % exc_str(exc))\n            return False\n\n    def _ask_field_value(self, f):\n        return ui.question(\n            f,\n            title=\"You need to authenticate with %r credentials.\" % self.name +\n                  \" %s provides information on how to gain access\"\n                  % self.url if self.url else '',\n            hidden=self._is_field_hidden(f))\n\n    def _ask_and_set(self, f):\n        v = self._ask_field_value(f)\n        self.set(**{f: v})\n        return v\n\n    def enter_new(self):\n        \"\"\"Enter new values for the credential fields\"\"\"\n        # Use ui., request credential fields corresponding to the type\n        for f in self._FIELDS:\n            if not self._is_field_optional(f):\n                self._ask_and_set(f)\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n        fields = {}\n        for f in self._FIELDS:\n            v = self._keyring.get(name, f)\n            if not self._is_field_optional(f):\n                while v is None:  # was not known\n                    v = self._ask_and_set(f)\n                fields[f] = v\n            elif v is not None:\n                fields[f] = v\n        return fields\n\n    def set(self, **kwargs):\n        \"\"\"Set field(s) of the credential\"\"\"\n        for f, v in kwargs.items():\n            if f not in self._FIELDS:\n                raise ValueError(\"Unknown field %s. Known are: %s\"\n                                 % (f, self._FIELDS.keys()))\n            self._keyring.set(self.name, f, v)\n\n    def get(self, f, default=None):\n        \"\"\"Get a field of the credential\"\"\"\n        if f not in self._FIELDS:\n            raise ValueError(\"Unknown field %s. Known are: %s\"\n                             % (f, self._FIELDS.keys()))\n        try:\n            return self._keyring.get(self.name, f)\n        except:\n            return default\n\n    def delete(self):\n        \"\"\"Deletes credential values from the keyring\"\"\"\n        for f in self._FIELDS:\n            self._keyring.delete(self.fname, f)\n\n\nclass UserPassword(Credential):\n    \"\"\"Simple type of a credential which consists of user/password pair\"\"\"\n\n    _FIELDS = OrderedDict([('user', {}),\n                           ('password', {'hidden': True})])\n\n    is_expired = False  # no expiration provisioned\n\n\nclass AWS_S3(Credential):\n    \"\"\"Credential for AWS S3 service\"\"\"\n\n    _FIELDS = OrderedDict([('key_id', {}),\n                           ('secret_id', {'hidden': True}),\n                           ('session', {'optional': True}),\n                           ('expiration', {'optional': True}),\n                           ])\n\n    @property\n    def is_expired(self):\n        exp = self.get('expiration', None)\n        if not exp:\n            return True\n        exp_epoch = iso8601_to_epoch(exp)\n        expire_in = (exp_epoch - calendar.timegm(time.localtime()))/3600.\n\n        lgr.debug(\n            (\"Credential %s has expired %.2fh ago\"\n                if expire_in <= 0 else \"Credential %s will expire in %.2fh\")\n            % (self.name, expire_in))\n        return expire_in <= 0\n\n\n@auto_repr\nclass CompositeCredential(Credential):\n    \"\"\"Credential which represent a sequence of Credentials where front one is exposed to user\n    \"\"\"\n\n    # To be defined in sub-classes\n    _CREDENTIAL_CLASSES = None\n    _CREDENTIAL_ADAPTERS = None\n\n    def _prepare(self):\n        assert len(self._CREDENTIAL_CLASSES) > 1, \"makes sense only if there is > 1 credential\"\n        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \\\n            \"there should be 1 less of adapter than _CREDENTIAL_CLASSES\"\n\n        for C in self._CREDENTIAL_CLASSES:\n            assert issubclass(C, Credential), \"%s must be a subclass of Credential\" % C\n\n        # First credential should bear the name and url\n        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]\n        # and we just reuse its _FIELDS for _ask_field_value etc\n        self._FIELDS = credentials[0]._FIELDS\n        # the rest with index suffix, but storing themselves in the same keyring\n        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):\n            credentials.append(C(name=\"%s:%d\" % (self.name, iC+1), url=None, keyring=self._keyring))\n        self._credentials = credentials\n\n        super(CompositeCredential, self)._prepare()\n\n    # Here it becomes tricky, since theoretically it is the \"tail\"\n    # ones which might expire etc, so we wouldn't exactly know what\n    # new credentials outside process wanted -- it would be silly to ask\n    # right away the \"entry\" credentials if it is just the expiration of the\n    # tail credentials\n    def enter_new(self):\n        # should invalidate/remove all tail credentials to avoid failing attempts to login\n        self._credentials[0].enter_new()\n        for c in self._credentials[1:]:\n            c.delete()\n\n    def __call__(self):\n        \"\"\"Obtain credentials from a keyring and if any is not known -- ask\"\"\"\n        name = self.name\n\n        # Start from the tail until we have credentials set\n        idx = len(self._credentials) - 1\n        for c in self._credentials[::-1]:\n            if c.is_known and not c.is_expired:\n                break\n            idx -= 1\n\n        if idx < 0:\n            # none was known, all the same -- start with the first one\n            idx = 0\n\n        # TODO: consider moving logic of traversal into authenticator since it is\n        # the one spitting out authentication error etc\n        # Theoretically we could just reuse 'fields' from adapter in the next step\n        # but let's do full circle, so that if any \"normalization\" is done by\n        # Credentials we take that into account\n        for c, adapter, next_c in zip(\n                self._credentials[idx:],\n                self._CREDENTIAL_ADAPTERS[idx:],\n                self._credentials[idx+1:]):\n            fields = c()\n            next_fields = adapter(**fields)\n            next_c.set(**next_fields)\n\n        return self._credentials[-1]()\n\n\ndef _nda_adapter(user=None, password=None):\n    from datalad.support.third.nda_aws_token_generator import NDATokenGenerator\n    gen = NDATokenGenerator()\n    token = gen.generate_token(user, password)\n    # There are also session and expiration we ignore... TODO anything about it?!!!\n    # we could create a derived AWS_S3 which would also store session and expiration\n    # and then may be Composite could use those????\n    return dict(key_id=token.access_key, secret_id=token.secret_key,\n                session=token.session, expiration=token.expiration)\n\n\nclass NDA_S3(CompositeCredential):\n    \"\"\"Credential to access NDA AWS\n\n    So for NDA we need a credential which is a composite credential.\n    User provides UserPassword and then some adapter generates AWS_S3\n    out of it\n    \"\"\"\n    _CREDENTIAL_CLASSES = (UserPassword, AWS_S3)\n    _CREDENTIAL_ADAPTERS = (_nda_adapter,)\n\n\nCREDENTIAL_TYPES = {\n    'user_password': UserPassword,\n    'aws-s3': AWS_S3,\n    'nda-s3': NDA_S3,\n}\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** AttributeError: 'UserPassword' object has no attribute 'fname' when deleting credentials

**Description:**
When attempting to delete a composite credential, an `AttributeError` is raised because the `UserPassword` object does not have a `fname` attribute. This prevents the credentials from being properly removed from the keyring.

**Example Code:**
```python
from datalad.downloaders.credentials import CompositeCredential, MemoryKeyring

keyring = MemoryKeyring()
cred = CompositeCredential("name", keyring=keyring)
cred.enter_new()
cred.delete()  # This line triggers the AttributeError
```

**Expected Behavior:**
The `delete` method should successfully remove all credential values associated with the given name from the keyring without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised:
```
AttributeError: 'UserPassword' object has no attribute 'fname'
```

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### datalad/downloaders/credentials.py
# emacs: -*- mode: python; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
# ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the datalad package for the
#   copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Interface information about credentials

Provides minimalistic interface to deal (query, request, store) with most common
types of credentials.  To be used by Authenticators
"""

__dev_doc__ = """
Possibly useful in the future 3rd part developments

https://github.com/omab/python-social-auth
    social authentication/registration mechanism with support for several
    frameworks and auth providers
"""

import time
import calendar

from collections import OrderedDict

from ..dochelpers import exc_str
from ..support.keyring_ import keyring as keyring_
from ..ui import ui
from ..utils import auto_repr
from ..support.network import iso8601_to_epoch

from logging import getLogger
lgr = getLogger('datalad.downloaders.credentials')


@auto_repr
class Credential(object):
    """Base class for different types of credentials
    """

    # Should be defined in a subclass as an OrderedDict of fields
    # name -> dict(attributes)
    _FIELDS = None
    _KNOWN_ATTRS = {
        'hidden',    # UI should not display the value
        'optional',  # Not mandatory thus not requested if not set
    }

    def __init__(self, name, url=None, keyring=None):
        """
        Parameters
        ----------
        name : str
            Name of the credential, as it would be identified by in the centralized
            storage of credentials
        url : str, optional
            URL string to point users to where to seek obtaining the credentials
        keyring : a keyring
            An object providing (g|s)et_password.  If None, keyring module is used
            as is
        """
        self.name = name
        self.url = url
        self._keyring = keyring or keyring_
        self._prepare()

    def _prepare(self):
        """Additional house-keeping possibly to be performed in subclasses

        Created to avoid all the passing args/kwargs of __init__ all the time
        """
        # Basic checks
        for f, fattrs in self._FIELDS.items():
            unknown_attrs = set(fattrs).difference(self._KNOWN_ATTRS)
            if unknown_attrs:
                raise ValueError("Unknown attributes %s. Known are: %s"
                                 % (unknown_attrs, self._KNOWN_ATTRS))

    def _is_field_optional(self, f):
        return self._FIELDS[f].get('optional', False)

    def _is_field_hidden(self, f):
        return self._FIELDS[f].get('hidden', False)

    @property
    def is_known(self):
        """Return True if values for all fields of the credential are known"""
        try:
            return all(
                self._is_field_optional(f) or self._keyring.get(self.name, f) is not None
                for f in self._FIELDS)
        except Exception as exc:
            lgr.warning("Failed to query keyring: %s" % exc_str(exc))
            return False

    def _ask_field_value(self, f):
        return ui.question(
            f,
            title="You need to authenticate with %r credentials." % self.name +
                  " %s provides information on how to gain access"
                  % self.url if self.url else '',
            hidden=self._is_field_hidden(f))

    def _ask_and_set(self, f):
        v = self._ask_field_value(f)
        self.set(**{f: v})
        return v

    def enter_new(self):
        """Enter new values for the credential fields"""
        # Use ui., request credential fields corresponding to the type
        for f in self._FIELDS:
            if not self._is_field_optional(f):
                self._ask_and_set(f)

    def __call__(self):
        """Obtain credentials from a keyring and if any is not known -- ask"""
        name = self.name
        fields = {}
        for f in self._FIELDS:
            v = self._keyring.get(name, f)
            if not self._is_field_optional(f):
                while v is None:  # was not known
                    v = self._ask_and_set(f)
                fields[f] = v
            elif v is not None:
                fields[f] = v
        return fields

    def set(self, **kwargs):
        """Set field(s) of the credential"""
        for f, v in kwargs.items():
            if f not in self._FIELDS:
                raise ValueError("Unknown field %s. Known are: %s"
                                 % (f, self._FIELDS.keys()))
            self._keyring.set(self.name, f, v)

    def get(self, f, default=None):
        """Get a field of the credential"""
        if f not in self._FIELDS:
            raise ValueError("Unknown field %s. Known are: %s"
                             % (f, self._FIELDS.keys()))
        try:
            return self._keyring.get(self.name, f)
        except:
            return default

    def delete(self):
        """Deletes credential values from the keyring"""
        for f in self._FIELDS:
            self._keyring.delete(self.fname, f)


class UserPassword(Credential):
    """Simple type of a credential which consists of user/password pair"""

    _FIELDS = OrderedDict([('user', {}),
                           ('password', {'hidden': True})])

    is_expired = False  # no expiration provisioned


class AWS_S3(Credential):
    """Credential for AWS S3 service"""

    _FIELDS = OrderedDict([('key_id', {}),
                           ('secret_id', {'hidden': True}),
                           ('session', {'optional': True}),
                           ('expiration', {'optional': True}),
                           ])

    @property
    def is_expired(self):
        exp = self.get('expiration', None)
        if not exp:
            return True
        exp_epoch = iso8601_to_epoch(exp)
        expire_in = (exp_epoch - calendar.timegm(time.localtime()))/3600.

        lgr.debug(
            ("Credential %s has expired %.2fh ago"
                if expire_in <= 0 else "Credential %s will expire in %.2fh")
            % (self.name, expire_in))
        return expire_in <= 0


@auto_repr
class CompositeCredential(Credential):
    """Credential which represent a sequence of Credentials where front one is exposed to user
    """

    # To be defined in sub-classes
    _CREDENTIAL_CLASSES = None
    _CREDENTIAL_ADAPTERS = None

    def _prepare(self):
        assert len(self._CREDENTIAL_CLASSES) > 1, "makes sense only if there is > 1 credential"
        assert len(self._CREDENTIAL_CLASSES) == len(self._CREDENTIAL_ADAPTERS) + 1, \
            "there should be 1 less of adapter than _CREDENTIAL_CLASSES"

        for C in self._CREDENTIAL_CLASSES:
            assert issubclass(C, Credential), "%s must be a subclass of Credential" % C

        # First credential should bear the name and url
        credentials = [self._CREDENTIAL_CLASSES[0](self.name, url=self.url, keyring=self._keyring)]
        # and we just reuse its _FIELDS for _ask_field_value etc
        self._FIELDS = credentials[0]._FIELDS
        # the rest with index suffix, but storing themselves in the same keyring
        for iC, C in enumerate(self._CREDENTIAL_CLASSES[1:]):
            credentials.append(C(name="%s:%d" % (self.name, iC+1), url=None, keyring=self._keyring))
        self._credentials = credentials

        super(CompositeCredential, self)._prepare()

    # Here it becomes tricky, since theoretically it is the "tail"
    # ones which might expire etc, so we wouldn't exactly know what
    # new credentials outside process wanted -- it would be silly to ask
    # right away the "entry" credentials if it is just the expiration of the
    # tail credentials
    def enter_new(self):
        # should invalidate/remove all tail credentials to avoid failing attempts to login
        self._credentials[0].enter_new()
        for c in self._credentials[1:]:
            c.delete()

    def __call__(self):
        """Obtain credentials from a keyring and if any is not known -- ask"""
        name = self.name

        # Start from the tail until we have credentials set
        idx = len(self._credentials) - 1
        for c in self._credentials[::-1]:
            if c.is_known and not c.is_expired:
                break
            idx -= 1

        if idx < 0:
            # none was known, all the same -- start with the first one
            idx = 0

        # TODO: consider moving logic of traversal into authenticator since it is
        # the one spitting out authentication error etc
        # Theoretically we could just reuse 'fields' from adapter in the next step
        # but let's do full circle, so that if any "normalization" is done by
        # Credentials we take that into account
        for c, adapter, next_c in zip(
                self._credentials[idx:],
                self._CREDENTIAL_ADAPTERS[idx:],
                self._credentials[idx+1:]):
            fields = c()
            next_fields = adapter(**fields)
            next_c.set(**next_fields)

        return self._credentials[-1]()


def _nda_adapter(user=None, password=None):
    from datalad.support.third.nda_aws_token_generator import NDATokenGenerator
    gen = NDATokenGenerator()
    token = gen.generate_token(user, password)
    # There are also session and expiration we ignore... TODO anything about it?!!!
    # we could create a derived AWS_S3 which would also store session and expiration
    # and then may be Composite could use those????
    return dict(key_id=token.access_key, secret_id=token.secret_key,
                session=token.session, expiration=token.expiration)


class NDA_S3(CompositeCredential):
    """Credential to access NDA AWS

    So for NDA we need a credential which is a composite credential.
    User provides UserPassword and then some adapter generates AWS_S3
    out of it
    """
    _CREDENTIAL_CLASSES = (UserPassword, AWS_S3)
    _CREDENTIAL_ADAPTERS = (_nda_adapter,)


CREDENTIAL_TYPES = {
    'user_password': UserPassword,
    'aws-s3': AWS_S3,
    'nda-s3': NDA_S3,
}

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user