<commit_before># -*- coding: utf-8 -*-

# Copyright(C) 2010  <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


from datetime import datetime, date, time
import HTMLParser

from weboob.tools.browser import BaseBrowser
from weboob.tools.misc import to_unicode

from .pages.route import RoutePage

class Route(object):
    "une ligne code_mission | time"
    def __init__(self, code_mission, time, destination, platform):
        self.code_mission = code_mission
        self.time = time
        self.destination = destination
        self.platform = platform

    def __repr__(self):
        return "<Route %s %s %s %s>" % (self.code_mission,
            self.time, self.destination, self.platform)

class Parser(HTMLParser.HTMLParser):
    "Parse les tableaux html contenant les horaires"
    def __init__(self):
        HTMLParser.HTMLParser.__init__(self)
        self.__table_horaires3 = False
        self.__code_de_mission = False
        self.__a_code_de_mission = False
        self.__time = False
        self.__destination = False
        self.__platform = False
        self.__liste_train = []
        self.__liste_horaire = []
        self.__liste_destination = []
        self.__liste_platform = []

    @classmethod
    def parse(cls, data, encoding):
        parser = cls()
        parser.feed(data.read())
        return parser

    def handle_starttag(self, tag, attrs):
        "execute a chaque balise ouvrante"
        if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
            self.__table_horaires3 = True

        elif self.__table_horaires3 and tag == 'td':
            try:
                self.__code_de_mission = (
                    dict(attrs)['headers'] == 'Code_de_mission')
                self.__time = (
                    dict(attrs)['headers'] == 'Heure_de_passage')
                self.__destination = (
                    dict(attrs)['headers'] == 'Destination')
                self.__platform = (
                    dict(attrs)['headers'] == 'Voie')
            except KeyError:
                if dict(attrs).has_key('headers'):
                    raise
                else:
                    pass
        else:
            self.__a_code_de_mission = (tag == 'a' and self.__code_de_mission)

    def handle_data(self, data):
        "execute pour chaque contenu de balise"
        if self.__a_code_de_mission:
            self.__liste_train.append(data.strip())
        if self.__time and data.strip() != '*':
            self.__liste_horaire.append(data.strip())
        if self.__destination:
            self.__liste_destination.append(data.strip())
        if self.__platform:
            self.__liste_platform.append(data.strip())

    def handle_endtag(self, tag):
        "execute à chaque balise fermante"
        self.__a_code_de_mission ^= (self.__a_code_de_mission and tag == 'a')
        self.__time ^= (self.__time and tag == 'td')
        self.__destination ^= (self.__destination and tag == 'td')
        self.__platform ^= (self.__platform and tag == 'td')


    @property
    def list_route(self):
        "getter"
        __list_route = []
        __curseur_horaire = 0
        for __i in self.__liste_train:
            __list_route.append(Route(
                code_mission=__i,
                time=self.__liste_horaire[__curseur_horaire],
                destination=self.__liste_destination[__curseur_horaire],
                platform=self.__liste_platform[__curseur_horaire]
                ))
            __curseur_horaire += 1
        return __list_route

class Transilien(BaseBrowser):
    DOMAIN = 'www.transilien.com'
    PAGES = {'https://www\.transilien\.com/web/ITProchainsTrainsAvecDest\.do\?.*': RoutePage,
             'https://www\.transilien\.com/web/ITProchainsTrains\.do\?.*': RoutePage
            }
    PROTOCOL = 'https'

    def __init__(self, **kwargs):
        kwargs['parser'] = Parser
        BaseBrowser.__init__(self, '', **kwargs)
        USER_AGENT = BaseBrowser.USER_AGENTS['microb']

    def iter_station_search(self, pattern):<commit_msg>fix pyflakes error on user agent<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2010  <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


from datetime import datetime, date, time
import HTMLParser

from weboob.tools.browser import BaseBrowser
from weboob.tools.misc import to_unicode

from .pages.route import RoutePage

class Route(object):
    "une ligne code_mission | time"
    def __init__(self, code_mission, time, destination, platform):
        self.code_mission = code_mission
        self.time = time
        self.destination = destination
        self.platform = platform

    def __repr__(self):
        return "<Route %s %s %s %s>" % (self.code_mission,
            self.time, self.destination, self.platform)

class Parser(HTMLParser.HTMLParser):
    "Parse les tableaux html contenant les horaires"
    def __init__(self):
        HTMLParser.HTMLParser.__init__(self)
        self.__table_horaires3 = False
        self.__code_de_mission = False
        self.__a_code_de_mission = False
        self.__time = False
        self.__destination = False
        self.__platform = False
        self.__liste_train = []
        self.__liste_horaire = []
        self.__liste_destination = []
        self.__liste_platform = []

    @classmethod
    def parse(cls, data, encoding):
        parser = cls()
        parser.feed(data.read())
        return parser

    def handle_starttag(self, tag, attrs):
        "execute a chaque balise ouvrante"
        if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
            self.__table_horaires3 = True

        elif self.__table_horaires3 and tag == 'td':
            try:
                self.__code_de_mission = (
                    dict(attrs)['headers'] == 'Code_de_mission')
                self.__time = (
                    dict(attrs)['headers'] == 'Heure_de_passage')
                self.__destination = (
                    dict(attrs)['headers'] == 'Destination')
                self.__platform = (
                    dict(attrs)['headers'] == 'Voie')
            except KeyError:
                if dict(attrs).has_key('headers'):
                    raise
                else:
                    pass
        else:
            self.__a_code_de_mission = (tag == 'a' and self.__code_de_mission)

    def handle_data(self, data):
        "execute pour chaque contenu de balise"
        if self.__a_code_de_mission:
            self.__liste_train.append(data.strip())
        if self.__time and data.strip() != '*':
            self.__liste_horaire.append(data.strip())
        if self.__destination:
            self.__liste_destination.append(data.strip())
        if self.__platform:
            self.__liste_platform.append(data.strip())

    def handle_endtag(self, tag):
        "execute à chaque balise fermante"
        self.__a_code_de_mission ^= (self.__a_code_de_mission and tag == 'a')
        self.__time ^= (self.__time and tag == 'td')
        self.__destination ^= (self.__destination and tag == 'td')
        self.__platform ^= (self.__platform and tag == 'td')


    @property
    def list_route(self):
        "getter"
        __list_route = []
        __curseur_horaire = 0
        for __i in self.__liste_train:
            __list_route.append(Route(
                code_mission=__i,
                time=self.__liste_horaire[__curseur_horaire],
                destination=self.__liste_destination[__curseur_horaire],
                platform=self.__liste_platform[__curseur_horaire]
                ))
            __curseur_horaire += 1
        return __list_route

class Transilien(BaseBrowser):
    DOMAIN = 'www.transilien.com'
    PAGES = {'https://www\.transilien\.com/web/ITProchainsTrainsAvecDest\.do\?.*': RoutePage,
             'https://www\.transilien\.com/web/ITProchainsTrains\.do\?.*': RoutePage
            }
    PROTOCOL = 'https'
    USER_AGENT = BaseBrowser.USER_AGENTS['microb']

    def __init__(self, **kwargs):
        kwargs['parser'] = Parser
        BaseBrowser.__init__(self, '', **kwargs)

    def iter_station_search(self, pattern):
{'fraction_non_alphanumeric': 0.10261333333333333, 'fraction_numerical': 0.005546666666666667, 'mean_word_length': 2.3485714285714288, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, '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': '3296552', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2635, 'n_words': 692}