sources for dupfile.py [rev. unknown]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
def dupfile(f, mode=None, buffering=0, raising=False): 
    """ return a new open file object that's a duplicate of f
        mode is duplicated if not given, 'buffering' controls 
        buffer size (defaulting to no buffering) and 'raising'
        defines whether an exception is raised when an incompatible
        file object is passed in (if raising is False, the file
        object itself will be returned)
    """
    try: 
        fd = f.fileno() 
    except AttributeError: 
        if raising: 
            raise 
        return f
    newfd = os.dup(fd) 
    mode = mode and mode or f.mode
    return os.fdopen(newfd, mode, buffering)