<commit_before>"""
urllib2.HTTPPasswordMgr object using the keyring, for use with the
urllib2.HTTPBasicAuthHandler.

usage:
    import urllib2
    handlers = [urllib2.HTTPBasicAuthHandler(PasswordMgr())]
    urllib2.install_opener(handlers)
    urllib2.urlopen(...)
    
This will prompt for a password if one is required and isn't already
in the keyring. Then, it adds it to the keyring for subsequent use.
"""

import keyring
import getpass

class PasswordMgr(object):
    def get_username(self, realm, authuri):
        return getpass.getuser()

    def find_user_password(self, realm, authuri):
        user = self.get_username(realm, authuri)
        passwd = keyring.get_password(authuri, user)
        if passwd is None:
            prompt = 'password for %(user)s@%(realm)s for '\
                '%(authuri)s: ' % vars()
            passwd = getpass.getpass(prompt)
            keyring.set_password(authuri, user, passwd)
        return user, passwd
<commit_msg>using the realm is more appropriate for the server field<commit_after>"""
urllib2.HTTPPasswordMgr object using the keyring, for use with the
urllib2.HTTPBasicAuthHandler.

usage:
    import urllib2
    handlers = [urllib2.HTTPBasicAuthHandler(PasswordMgr())]
    urllib2.install_opener(handlers)
    urllib2.urlopen(...)
    
This will prompt for a password if one is required and isn't already
in the keyring. Then, it adds it to the keyring for subsequent use.
"""

import keyring
import getpass

class PasswordMgr(object):
    def get_username(self, realm, authuri):
        return getpass.getuser()

    def find_user_password(self, realm, authuri):
        user = self.get_username(realm, authuri)
        passwd = keyring.get_password(realm, user)
        if passwd is None:
            prompt = 'password for %(user)s@%(realm)s for '\
                '%(authuri)s: ' % vars()
            passwd = getpass.getpass(prompt)
            keyring.set_password(realm, user, passwd)
        return user, passwd
{'fraction_non_alphanumeric': 0.09292929292929293, 'fraction_numerical': 0.006060606060606061, 'mean_word_length': 3.1185031185031185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6109499', 'n_tokens_mistral': 625, 'n_tokens_neox': 624, 'n_words': 179}