File size: 462 Bytes
db2c7db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Failure handling around an object that reads.

One handler catches every exception the interpreter can raise, and that is the shape
the narrow exception pattern rewrites. The other handler already names its exception,
and the pattern says so.
"""


def call_or_none(source):
    try:
        return source.read()
    except:
        return ""


def call_or_note(source):
    try:
        return source.read()
    except ValueError:
        return "no source"