Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:replace some generic Exceptions with slightly less generic BabelErrors
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:90294f94685bdce54b305a0d41268b2d3637dda5
User & Date: brandon 2015-05-05 21:53:00
Context
2015-05-05
22:12
catch unsupported cover images in blorbs check-in: 006876d44a user: brandon tags: trunk
21:53
replace some generic Exceptions with slightly less generic BabelErrors check-in: 90294f9468 user: brandon tags: trunk
2015-01-25
22:28
more "contacts" fixes check-in: 3ee30d8364 user: brandon tags: trunk
Changes

Changes to treatyofbabel/formats/quest.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
23
24
25
26
27
28
29

30
31
32
33
34
35
36
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
#
#       quest.py
#
#       Copyright © 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
import md5
import xml.dom.minidom
import zipfile
from cStringIO import StringIO
from binascii import hexlify

from treatyofbabel import ifiction



FORMAT = "quest"
FORMAT_EXT = [".quest"]
HOME_PAGE = "http://www.textadventures.co.uk"
HAS_COVER = False
HAS_META = True
................................................................................


def get_story_file_meta(file_buffer, truncate=False):
    aslx = _extract_aslx(file_buffer)
    aslx_dom = xml.dom.minidom.parseString(aslx)
    aslx_games = aslx_dom.getElementsByTagName("game")
    if len(aslx_games) == 0:
        raise Exception("No game information found")
    aslx_game = aslx_games[0]
    gameinfo = ifiction.build_dict_from_node(aslx_game)
    ifiction_dom = ifiction.create_ifiction_dom()
    ifiction.add_comment(ifiction_dom,
                         "Bibliographic data translated from Quest ASLX")
    story_node = ifiction.add_story(ifiction_dom)
    title = aslx_game.getAttribute("name")
................................................................................


def get_story_file_ifid(file_buffer):
    aslx = _extract_aslx(file_buffer)
    aslx_dom = xml.dom.minidom.parseString(aslx)
    aslx_games = aslx_dom.getElementsByTagName("game")
    if len(aslx_games) == 0:
        raise Exception("No game information found")
    aslx_game = aslx_games[0]
    gameinfo = ifiction.build_dict_from_node(aslx_game)
    ifid = gameinfo.get("gameid")
    if ifid is None:
        file_hash = hexlify(md5.new(file_buffer).digest()).upper()
        ifid = "QUEST-{0}".format(file_hash)
    return ifid




|







 







>







 







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
#
#       quest.py
#
#       Copyright © 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
import md5
import xml.dom.minidom
import zipfile
from cStringIO import StringIO
from binascii import hexlify

from treatyofbabel import ifiction
from treatyofbabel.babelerrors import BabelError


FORMAT = "quest"
FORMAT_EXT = [".quest"]
HOME_PAGE = "http://www.textadventures.co.uk"
HAS_COVER = False
HAS_META = True
................................................................................


def get_story_file_meta(file_buffer, truncate=False):
    aslx = _extract_aslx(file_buffer)
    aslx_dom = xml.dom.minidom.parseString(aslx)
    aslx_games = aslx_dom.getElementsByTagName("game")
    if len(aslx_games) == 0:
        raise BabelError("No game information found")
    aslx_game = aslx_games[0]
    gameinfo = ifiction.build_dict_from_node(aslx_game)
    ifiction_dom = ifiction.create_ifiction_dom()
    ifiction.add_comment(ifiction_dom,
                         "Bibliographic data translated from Quest ASLX")
    story_node = ifiction.add_story(ifiction_dom)
    title = aslx_game.getAttribute("name")
................................................................................


def get_story_file_ifid(file_buffer):
    aslx = _extract_aslx(file_buffer)
    aslx_dom = xml.dom.minidom.parseString(aslx)
    aslx_games = aslx_dom.getElementsByTagName("game")
    if len(aslx_games) == 0:
        raise BabelError("No game information found")
    aslx_game = aslx_games[0]
    gameinfo = ifiction.build_dict_from_node(aslx_game)
    ifid = gameinfo.get("gameid")
    if ifid is None:
        file_hash = hexlify(md5.new(file_buffer).digest()).upper()
        ifid = "QUEST-{0}".format(file_hash)
    return ifid

Changes to treatyofbabel/formats/tads2.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
25
26
27
28
29
30
31

32
33
34
35
36
37
38
...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -*-
#
#       tads2.py
#
#       Copyright © 2011, 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
................................................................................
import md5
import os.path
from binascii import hexlify

from treatyofbabel.utils._binaryfuncs import read_int, read_short, read_byte
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel import ifiction



FORMAT = "tads2"
FORMAT_EXT = [".gam"]
HOME_PAGE = "http://www.tads.org"
HAS_COVER = True
HAS_META = True
................................................................................
        if cover_resc:
            ext = os.path.splitext(resc_name)[1].strip('.')
            if ext == 'jpg':
                (width, height) = get_jpeg_dim(cover_resc)
            else:
                (width, height) = get_png_dim(cover_resc)
            if width is None or height is None:
                raise Exception("Image corrupted: cannot determine dimensions")
            cover = CoverImage(cover_resc, ext, width, height, None)
            return cover
    return None


def get_story_file_ifid(file_buffer):
    if not claim_story_file(file_buffer):




|







 







>







 







|







1
2
3
4
5
6
7
8
9
10
11
12
..
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
#
#       tads2.py
#
#       Copyright © 2011, 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
................................................................................
import md5
import os.path
from binascii import hexlify

from treatyofbabel.utils._binaryfuncs import read_int, read_short, read_byte
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel import ifiction
from treatyofbabel.babelerrors import BabelError


FORMAT = "tads2"
FORMAT_EXT = [".gam"]
HOME_PAGE = "http://www.tads.org"
HAS_COVER = True
HAS_META = True
................................................................................
        if cover_resc:
            ext = os.path.splitext(resc_name)[1].strip('.')
            if ext == 'jpg':
                (width, height) = get_jpeg_dim(cover_resc)
            else:
                (width, height) = get_png_dim(cover_resc)
            if width is None or height is None:
                raise BabelError("Image corrupted: cannot determine dimensions")
            cover = CoverImage(cover_resc, ext, width, height, None)
            return cover
    return None


def get_story_file_ifid(file_buffer):
    if not claim_story_file(file_buffer):

Changes to treatyofbabel/formats/tads3.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
25
26
27
28
29
30
31

32
33
34
35
36
37
38
...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -*-
#
#       tads3.py
#
#       Copyright © 2011, 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
................................................................................
import md5
import os.path
from binascii import hexlify

from treatyofbabel.utils._binaryfuncs import read_int, read_short, read_byte
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel import ifiction



FORMAT = "tads3"
FORMAT_EXT = [".t3"]
HOME_PAGE = "http://www.tads.org"
HAS_COVER = True
HAS_META = True
................................................................................
        if cover_resc:
            ext = os.path.splitext(resc_name)[1].strip('.')
            if ext == 'jpg':
                (width, height) = get_jpeg_dim(cover_resc)
            else:
                (width, height) = get_png_dim(cover_resc)
            if width is None or height is None:
                raise Exception("Image corrupted: cannot determine dimensions")
            cover = CoverImage(cover_resc, ext, width, height, None)
            return cover
    return None


def get_story_file_ifid(file_buffer):
    if not claim_story_file(file_buffer):




|







 







>







 







|







1
2
3
4
5
6
7
8
9
10
11
12
..
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
#
#       tads3.py
#
#       Copyright © 2011, 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
................................................................................
import md5
import os.path
from binascii import hexlify

from treatyofbabel.utils._binaryfuncs import read_int, read_short, read_byte
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel import ifiction
from treatyofbabel.babelerrors import BabelError


FORMAT = "tads3"
FORMAT_EXT = [".t3"]
HOME_PAGE = "http://www.tads.org"
HAS_COVER = True
HAS_META = True
................................................................................
        if cover_resc:
            ext = os.path.splitext(resc_name)[1].strip('.')
            if ext == 'jpg':
                (width, height) = get_jpeg_dim(cover_resc)
            else:
                (width, height) = get_png_dim(cover_resc)
            if width is None or height is None:
                raise BabelError("Image corrupted: cannot determine dimensions")
            cover = CoverImage(cover_resc, ext, width, height, None)
            return cover
    return None


def get_story_file_ifid(file_buffer):
    if not claim_story_file(file_buffer):

Changes to treatyofbabel/ifstory.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# -*- coding: utf-8 -*-
#
#       ifstory.py
#
#       Copyright © 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
import os.path
from urllib2 import urlopen
import time

import ifiction
import treatyofbabel
from utils._imgfuncs import CoverImage, get_png_dim, get_jpeg_dim
from babelerrors import IFictionError
from treatyofbabel import PYIFBABEL_VERSION


class StrictDict(dict):
    """A derivative of the dict class whose legal keys must be declared at
    initialization.

................................................................................
        # try to get the tuid if it exists
        elif tuid is None and len(self.annotation) > 0:
            ifdb_annot = self.annotation.get("ifdb")
            if ifdb_annot is not None:
                tuid = ifdb_annot.get("tuid")
        # Access the IFDB public API
        if ifid is None and tuid is None:
            raise Exception("No IFID or TUID set")
        if tuid is not None:
            url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&id=',
                           tuid])
        else:
            url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&ifid=',
                           ifid])
        ific = urlopen(url)




|







 







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# -*- coding: utf-8 -*-
#
#       ifstory.py
#
#       Copyright © 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel 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, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
import os.path
from urllib2 import urlopen
import time

import ifiction
import treatyofbabel
from utils._imgfuncs import CoverImage, get_png_dim, get_jpeg_dim
from babelerrors import IFictionError, BabelError
from treatyofbabel import PYIFBABEL_VERSION


class StrictDict(dict):
    """A derivative of the dict class whose legal keys must be declared at
    initialization.

................................................................................
        # try to get the tuid if it exists
        elif tuid is None and len(self.annotation) > 0:
            ifdb_annot = self.annotation.get("ifdb")
            if ifdb_annot is not None:
                tuid = ifdb_annot.get("tuid")
        # Access the IFDB public API
        if ifid is None and tuid is None:
            raise BabelError("No IFID or TUID set")
        if tuid is not None:
            url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&id=',
                           tuid])
        else:
            url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&ifid=',
                           ifid])
        ific = urlopen(url)

Changes to treatyofbabel/wrappers/blorb.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# -*- coding: utf-8 -*-
#
#       blorb.py
#
#       Copyright © 2011, 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of Grotesque.
#
#       Grotesque 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, either version 3 of the License, or
................................................................................
from ctypes import create_string_buffer
import os
import struct

from treatyofbabel.utils._binaryfuncs import read_int
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel.utils._imgfuncs import deduce_img_format
import treatyofbabel.ifiction as ifiction


FORMAT = "blorb"
FORMAT_EXT = [".blorb", ".blb", ".zblorb", ".zlb", ".gblorb", ".glb"]
HOME_PAGE = "http://eblong.com/zarf/blorb"


def get_format_name():
................................................................................
    if cover_format == "PNG":
        ext = "png"
        (width, height) = get_png_dim(cover_data)
    elif cover_format == "JPEG":
        ext = "jpg"
        (width, height) = get_jpeg_dim(cover_data)
    if width is None or height is None:
        raise Exception("Image corrupted: cannot determine dimensions")
    cover = CoverImage(cover_data, ext, width, height, description)
    return cover


def get_story_file_ifid(file_buffer):
    meta = get_story_file_meta(file_buffer)
    if meta is None:
................................................................................
                       "tads3": "TAD3", "hugo": "HUGO", "alan": "ALAN",
                       "adrift": "ADRI", "level9": "LEVE", "agt": "AGT",
                       "magscrolls": "MAGS", "advsys": "ADVS",
                       "executable": "EXEC"}
    story_len = os.path.getsize(story_file)
    frmt = treaty_registry.get(story_format)
    if frmt is None:
        raise Exception("Unsupported story format")
    if coverart_file is not None:
        cover_len = os.path.getsize(coverart_file)
        ridx_num = 2
        with open(coverart_file) as h:
            image_data = h.read()
            cover_frmt = deduce_img_format(image_data)
        if cover_frmt is None:
            raise Exception("Unsupported or broken image format")
        elif cover_frmt == "png":
            cover_frmt = "PNG "
        else:
            cover_frmt = "JPEG"
    else:
        cover_len = 0
        ridx_num = 1
................................................................................
    elif story_format == "magscrolls":
        from treatyofbabel.formats import magscrolls as handler
    elif story_format == "advsys":
        from treatyofbabel.formats import advsys as handler
    elif story_format == "executable":
        from treatyofbabel.formats import executable as handler
    else:
        raise Exception("Unknown story format")
    return handler.get_story_file_ifid(story_file)


def _get_chunk(file_buffer, chunk_id):
    i = 12
    while i < len(file_buffer) - 8:
        length = read_int(file_buffer, i + 4)




|







 







|
|







 







|







 







|







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# -*- coding: utf-8 -*-
#
#       blorb.py
#
#       Copyright © 2011, 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#
#       This file is part of Grotesque.
#
#       Grotesque 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, either version 3 of the License, or
................................................................................
from ctypes import create_string_buffer
import os
import struct

from treatyofbabel.utils._binaryfuncs import read_int
from treatyofbabel.utils._imgfuncs import CoverImage, get_jpeg_dim, get_png_dim
from treatyofbabel.utils._imgfuncs import deduce_img_format
from treatyofbabel import ifiction
from treatyofbabel.babelerrors import BabelError

FORMAT = "blorb"
FORMAT_EXT = [".blorb", ".blb", ".zblorb", ".zlb", ".gblorb", ".glb"]
HOME_PAGE = "http://eblong.com/zarf/blorb"


def get_format_name():
................................................................................
    if cover_format == "PNG":
        ext = "png"
        (width, height) = get_png_dim(cover_data)
    elif cover_format == "JPEG":
        ext = "jpg"
        (width, height) = get_jpeg_dim(cover_data)
    if width is None or height is None:
        raise BabelError("Image corrupted: cannot determine dimensions")
    cover = CoverImage(cover_data, ext, width, height, description)
    return cover


def get_story_file_ifid(file_buffer):
    meta = get_story_file_meta(file_buffer)
    if meta is None:
................................................................................
                       "tads3": "TAD3", "hugo": "HUGO", "alan": "ALAN",
                       "adrift": "ADRI", "level9": "LEVE", "agt": "AGT",
                       "magscrolls": "MAGS", "advsys": "ADVS",
                       "executable": "EXEC"}
    story_len = os.path.getsize(story_file)
    frmt = treaty_registry.get(story_format)
    if frmt is None:
        raise BabelError("Unsupported story format")
    if coverart_file is not None:
        cover_len = os.path.getsize(coverart_file)
        ridx_num = 2
        with open(coverart_file) as h:
            image_data = h.read()
            cover_frmt = deduce_img_format(image_data)
        if cover_frmt is None:
            raise BabelError("Unsupported or broken image format")
        elif cover_frmt == "png":
            cover_frmt = "PNG "
        else:
            cover_frmt = "JPEG"
    else:
        cover_len = 0
        ridx_num = 1
................................................................................
    elif story_format == "magscrolls":
        from treatyofbabel.formats import magscrolls as handler
    elif story_format == "advsys":
        from treatyofbabel.formats import advsys as handler
    elif story_format == "executable":
        from treatyofbabel.formats import executable as handler
    else:
        raise BabelError("Unknown story format")
    return handler.get_story_file_ifid(story_file)


def _get_chunk(file_buffer, chunk_id):
    i = 12
    while i < len(file_buffer) - 8:
        length = read_int(file_buffer, i + 4)