~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Lib/linecache.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
    if filename in cache:
75
75
        del cache[filename]
76
 
    if not filename or filename[0] + filename[-1] == '<>':
 
76
    if not filename or (filename.startswith('<') and filename.endswith('>')):
77
77
        return []
78
78
 
79
79
    fullname = filename
80
80
    try:
81
81
        stat = os.stat(fullname)
82
 
    except os.error as msg:
 
82
    except OSError:
83
83
        basename = filename
84
84
 
85
85
        # Try for a __loader__, if available
114
114
                fullname = os.path.join(dirname, basename)
115
115
            except (TypeError, AttributeError):
116
116
                # Not sufficiently string-like to do anything useful with.
 
117
                continue
 
118
            try:
 
119
                stat = os.stat(fullname)
 
120
                break
 
121
            except os.error:
117
122
                pass
118
 
            else:
119
 
                try:
120
 
                    stat = os.stat(fullname)
121
 
                    break
122
 
                except os.error:
123
 
                    pass
124
123
        else:
125
 
            # No luck
126
124
            return []
127
 
    with open(fullname, 'rb') as fp:
128
 
        coding, line = tokenize.detect_encoding(fp.readline)
129
 
    with open(fullname, 'r', encoding=coding) as fp:
130
 
        lines = fp.readlines()
 
125
    try:
 
126
        with open(fullname, 'rb') as fp:
 
127
            coding, line = tokenize.detect_encoding(fp.readline)
 
128
        with open(fullname, 'r', encoding=coding) as fp:
 
129
            lines = fp.readlines()
 
130
    except IOError:
 
131
        pass
 
132
    if lines and not lines[-1].endswith('\n'):
 
133
        lines[-1] += '\n'
131
134
    size, mtime = stat.st_size, stat.st_mtime
132
135
    cache[filename] = size, mtime, lines, fullname
133
136
    return lines