'Optionally attempt to get a device id using the old cookie method.
Must have _winreg installed on Windows machines for successful key retrieval.'

def __oldcookiedeviceid(self):

    wsuid = ''
    pwsdid = ''
    try:
        if sys.platform.startswith('win'):
            import _winreg
            regkey_browser = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\\Kobo\\Kobo    Desktop    Edition\\Browser')
            cookies = _winreg.QueryValueEx(regkey_browser, 'cookies')
            bytearrays = cookies[0]
        elif sys.platform.startswith('darwin'):
            prefs = os.path.join(os.environ['HOME'], 'Library/Preferences/com.kobo.Kobo    Desktop    Edition.plist')
            cookies = self.plist_to_dictionary(prefs)
            bytearrays = cookies['Browser.cookies']
        for bytearr in bytearrays:
            cookie = self.__bytearraytostring(bytearr)
            wsuidcheck = re.match('^wsuid=([0-9a-f-]+)', cookie)
            if wsuidcheck:
                wsuid = wsuidcheck.group(1)
            pwsdidcheck = re.match('^pwsdid=([0-9a-f-]+)', cookie)
            if pwsdidcheck:
                pwsdid = pwsdidcheck.group(1)
        if ((wsuid == '') or (pwsdid == '')):
            return None
        preuserkey = string.join((pwsdid, wsuid), '')
        userkey = hashlib.sha256(preuserkey).hexdigest()
        return binascii.a2b_hex(userkey[32:])
    except KeyError:
        print 'No    "cookies"    key    found    in    Kobo    plist:    no    legacy    user    key    found.'
        return None
    except:
        print 'Error    parsing    Kobo    plist:    no    legacy    user    key    found.'
        return None
