~marco-gallotta/ibid/ascii-501638

« back to all changes in this revision

Viewing changes to ibid/plugins/ascii.py

  • Committer: Marco Gallotta
  • Date: 2010-01-04 11:26:02 UTC
  • Revision ID: marco@me-20100104112602-svusjzzey3j8i9bi
Improved exception handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
    @match(r'^draw\s+(\S+\.\S+)(\s+in\s+colou?r)?(?:\s+w(?:idth)?\s+(\d+))?(?:\s+h(?:eight)\s+(\d+))?$')
45
45
    def draw(self, event, url, colour, width, height):
46
 
        f = urlopen(url)
 
46
        try:
 
47
            f = urlopen(url)
 
48
        except ValueError:
 
49
            return # ignore if we can't get the URL
47
50
 
48
51
        filesize = int(f.info().getheaders('Content-Length')[0])
49
52
        if filesize > self.max_filesize * 1024:
59
62
 
60
63
            try:
61
64
                img = Image.open(StringIO(open(image, 'r').read())).convert('L')
62
 
            except:
63
 
                event.addresponse(u'Cannot understand image format')
 
65
            except IOError:
 
66
                event.addresponse(u"Sorry, I can't draw that for you!")
64
67
                return
65
68
            input_width, input_height = img.size[0], img.size[1]
66
69
 
100
103
    def draw_aa(self, event, image, width, height):
101
104
        try:
102
105
            image = Image.open(StringIO(open(image, 'r').read())).convert('L')
103
 
        except:
104
 
            event.addresponse(u'Cannot understand image format')
 
106
        except IOError:
 
107
            event.addresponse(u"Sorry, I can't draw that for you!")
105
108
            return
106
109
        screen = AsciiScreen(width=width, height=height)
107
110
        image = image.resize(screen.virtual_size)
118
121
        if code == 0:
119
122
            event.addresponse(unicode(response.replace('\r', '')), address=False, conflate=False)
120
123
        else:
121
 
            event.addresponse(u'Sorry, cannot understand image format')
 
124
            event.addresponse(u"Sorry, I can't draw that for you!")
122
125
 
123
126
class WriteFiglet(Processor):
124
127
    u"""figlet <text> [in <font>]
125
128
    list figlet fonts [from <index>]"""
126
129
    feature = 'figlet'
127
130
 
128
 
    fonts_zip = Option('fonts_zip', 'Zip file containing figlet fonts', 'data/figlet-fonts.zip')
 
131
    fonts_zip = Option('fonts_zip', 'Zip file containing figlet fonts', 'ibid/data/figlet-fonts.zip')
129
132
 
130
133
    def __init__(self, name):
131
134
        Processor.__init__(self, name)