# -*- coding: utf-8 -*- # Copyright(C) 2013 Laurent Bachelier # # This file is part of a weboob module. # # This weboob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This weboob module is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . from ast import literal_eval from decimal import Decimal, ROUND_DOWN import re from weboob.tools.compat import unicode, unquote from weboob.capabilities.bank import Account from weboob.capabilities.base import NotAvailable from weboob.exceptions import BrowserUnavailable, ActionNeeded from weboob.browser.exceptions import ServerError from weboob.browser.pages import HTMLPage, JsonPage, LoggedPage from weboob.browser.filters.standard import CleanText, CleanDecimal from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.date import parse_french_date from weboob.tools.js import Javascript class LandingPage(HTMLPage): pass class OldWebsitePage(LoggedPage, HTMLPage): pass class InfoPage(HTMLPage): def on_load(self): raise ActionNeeded(CleanText('//h1[@class="falconHeaderText"]')(self.doc)) class PromoPage(LoggedPage, HTMLPage): def on_load(self): # We land sometimes on this page, it's better to raise an unavailable browser # than an Incorrect Password raise BrowserUnavailable('Promo Page') class LoginPage(HTMLPage): def get_token_and_csrf(self, code): # Paypal will try to create an infinite loop to make the parse fail, based on different # weird things like a check of 'ind\\u0435xOf' vs 'indexOf'. cleaner_code = code.replace(r"'ind\\u0435xOf'", "'indexOf'") # It also calls "data" which is undefined instead of a return (next call is an infinite # recursive function). This should theorically not happen if window.domain is correctly set # to "paypal.com" though. cleaner_code = cleaner_code.replace("data;", "return;") # Remove setCookie function content cleaner_code = re.sub(r"'setCookie'.*(?=,'removeCookie')", "'setCookie':function(){}", cleaner_code) # Paypal will try to send a XHR, let's use a fake method to catch the values sent cleaner_code = """ XMLHttpRequest.prototype.send = function(body) { window.PAYPAL_TOKENS = body; }; function GET_JS_TOKENS() { return window.PAYPAL_TOKENS || "INVALID_TOKENS"; } """ + cleaner_code try: raw = str(Javascript(cleaner_code, None, "paypal.com").call("GET_JS_TOKENS")) raw = raw.split("&") tokens = {} for r in raw: r = r.split("=") k = r[0] v = unquote(r[1]) if k not in ["ads_token_js", "_sessionID", "_csrf"]: tokens["key"] = k tokens["value"] = v else: tokens[k] = v token = tokens["ads_token_js"] sessionID = tokens["_sessionID"] csrf = tokens["_csrf"] key = tokens["key"] value = tokens["value"] except: raise BrowserUnavailable("Could not grab tokens") # Clean string obfuscation like: '\x70\x61\x79\x70\x61\x6c\x20\x73\x75\x63\x6b\x73' def basic_decoder(mtc): return repr(literal_eval(mtc.group(0)).encode('utf-8')) cleaner_code = re.sub(r"'.*?(?