

def get_pin_and_cookie_name(app):
    'Given an application object this returns a semi-stable 9 digit pin\n    code and a random key.  The hope is that this is stable between\n    restarts to not make debugging particularly frustrating.  If the pin\n    was forcefully disabled this returns `None`.\n\n    Second item in the resulting tuple is the cookie name for remembering.\n    '
    pin = os.environ.get('WERKZEUG_DEBUG_PIN')
    rv = None
    num = None
    if (pin == 'off'):
        return (None, None)
    if ((pin is not None) and pin.replace('-', '').isdigit()):
        if ('-' in pin):
            rv = pin
        else:
            num = pin
    modname = getattr(app, '__module__', getattr(app.__class__, '__module__'))
    bits = [getpass.getuser(), str(uuid.getnode()), modname, getattr(app, '__name__', getattr(app.__class__, '__name__'))]
    mod = sys.modules.get(modname)
    bits.append(getattr(mod, '__file__', None))
    h = hashlib.md5()
    for bit in bits:
        if (not bit):
            continue
        if isinstance(bit, text_type):
            bit = bit.encode('utf-8')
        h.update(bit)
    if (num is None):
        num = ('%09d' % int(h.hexdigest(), 16))[:9]
    h.update('cookiesalt')
    cookie_name = ('__wzd' + h.hexdigest()[:12])
    if (rv is None):
        for group_size in (5, 4, 3):
            if ((len(num) % group_size) == 0):
                rv = '-'.join((num[x:(x + group_size)].rjust(group_size, '0') for x in range(0, len(num), group_size)))
                break
        else:
            rv = num
    return (rv, cookie_name)

dataset/ETHPy150Open GoogleCloudPlatform/appengine-flask-skeleton/lib/werkzeug/debug/__init__.py get_pin_and_cookie_name/original