# Path: fladgejt/helpers.py
# class CantOpenApplication(Exception):
#     '''AIS didn't open the application we wanted.
# 
#     Thrown from ``_open_...`` methods if AIS refuses to open the application
#     (e.g. the menu item is disabled for this user). The caller should catch
#     this and show a message to the user. This is only used when we know it can
#     happen -- unknown AIS behavior will cause an AISBehaviorError.
#     '''
# 
# def decode_key(string):
#     '''Decode the output of :func:`encode_key` back into a tuple of strings.
# 
#     See :func:`keyed_namedtuple` for the rationale.
# 
#     Args:
#         string: A string created with :func:`encode_key`.
#     Returns:
#         The tuple of strings that was originally given to :func:`encode_key`.
#     '''
#     result = []
#     for part in string.split('.'):
#         part = part.encode('ascii')
#         part += b'=' * (-len(part) % 4)
#         part = urlsafe_b64decode(part)
#         part = part.decode('utf8')
#         result.append(part)
#     return tuple(result)
# 
# Path: fladgejt/structures.py



from fladgejt.helpers import CantOpenApplication, decode_key
from fladgejt.structures import Hodnotenie, Priemer, PriebezneHodnotenie, PriebezneHodnoteniaPredmetu
                             hodn_znamka_popis=row['znamkaPopis'],
                             zapisny_list_key=zapisny_list_key)
                  for row in app.d.hodnoteniaTable.all_rows()]
        return [result, None]
        # TODO: Hmm, Fajr mozno pouziva aj 'uznane'

    def get_priemery(self, zapisny_list_key):
        try:
            app = self._open_hodnotenia_priemery_app(zapisny_list_key)
        except CantOpenApplication:
            return [[], "Priemery pre toto štúdium nie sú dostupné."]

        app.freshly_opened = False

        result = [Priemer(akademicky_rok=row['priemerInfoPopisAkadRok'],
                          nazov=row['priemerNazov'],
                          semester=row['semesterKodJ'],
                          ziskany_kredit=row['ziskanyKredit'],
                          predmetov=row['pocetPredmetov'],
                          neabsolvovanych=row['pocetNeabs'],
                          studijny_priemer=row['studPriemer'],
                          vazeny_priemer=row['vazPriemer'],
                          pokusy_priemer=row['pokusyPriemer'],
                          datum_vypoctu=row['priemerInfoDatum'])
                  for row in app.d.priemeryTable.all_rows()]
        return [result, None]

    def get_priebezne_hodnotenia(self, zapisny_list_key):
        try:
            app = self._open_priebezne_hodnotenie_app(zapisny_list_key)

# Path: fladgejt/helpers.py
# class CantOpenApplication(Exception):
#     '''AIS didn't open the application we wanted.
# 
#     Thrown from ``_open_...`` methods if AIS refuses to open the application
#     (e.g. the menu item is disabled for this user). The caller should catch
#     this and show a message to the user. This is only used when we know it can
#     happen -- unknown AIS behavior will cause an AISBehaviorError.
#     '''
# 
# def decode_key(string):
#     '''Decode the output of :func:`encode_key` back into a tuple of strings.
# 
#     See :func:`keyed_namedtuple` for the rationale.
# 
#     Args:
#         string: A string created with :func:`encode_key`.
#     Returns:
#         The tuple of strings that was originally given to :func:`encode_key`.
#     '''
#     result = []
#     for part in string.split('.'):
#         part = part.encode('ascii')
#         part += b'=' * (-len(part) % 4)
#         part = urlsafe_b64decode(part)
#         part = part.decode('utf8')
#         result.append(part)
#     return tuple(result)
# 
# Path: fladgejt/structures.py



# Path: fladgejt/webui/hodnotenia.py
from fladgejt.helpers import CantOpenApplication, decode_key
from fladgejt.structures import Hodnotenie, Priemer, PriebezneHodnotenie, PriebezneHodnoteniaPredmetu

                             hodn_znamka_popis=row['znamkaPopis'],
                             zapisny_list_key=zapisny_list_key)
                  for row in app.d.hodnoteniaTable.all_rows()]
        return [result, None]
        # TODO: Hmm, Fajr mozno pouziva aj 'uznane'

    def get_priemery(self, zapisny_list_key):
        try:
            app = self._open_hodnotenia_priemery_app(zapisny_list_key)
        except CantOpenApplication:
            return [[], "Priemery pre toto štúdium nie sú dostupné."]

        app.freshly_opened = False

        result = [Priemer(akademicky_rok=row['priemerInfoPopisAkadRok'],
                          nazov=row['priemerNazov'],
                          semester=row['semesterKodJ'],
                          ziskany_kredit=row['ziskanyKredit'],
                          predmetov=row['pocetPredmetov'],
                          neabsolvovanych=row['pocetNeabs'],
                          studijny_priemer=row['studPriemer'],
                          vazeny_priemer=row['vazPriemer'],
                          pokusy_priemer=row['pokusyPriemer'],
                          datum_vypoctu=row['priemerInfoDatum'])
                  for row in app.d.priemeryTable.all_rows()]
        return [result, None]

    def get_priebezne_hodnotenia(self, zapisny_list_key):
        try:
            app = self._open_priebezne_hodnotenie_app(zapisny_list_key)

        except CantOpenApplication: