| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,21 +61,19 @@ def main(): | |||
| 61 | 61 | else: optfile = "Lib/keyword.py" | |
| 62 | 62 | ||
| 63 | 63 | # scan the source file for keywords | |
| 64 | - fp = open(iptfile) | ||
| 65 | - strprog = re.compile('"([^"]+)"') | ||
| 66 | - lines = [] | ||
| 67 | - for line in fp: | ||
| 68 | - if '{1, "' in line: | ||
| 69 | - match = strprog.search(line) | ||
| 70 | - if match: | ||
| 71 | - lines.append(" '" + match.group(1) + "',\n") | ||
| 72 | - fp.close() | ||
| 64 | + with open(iptfile) as fp: | ||
| 65 | + strprog = re.compile('"([^"]+)"') | ||
| 66 | + lines = [] | ||
| 67 | + for line in fp: | ||
| 68 | + if '{1, "' in line: | ||
| 69 | + match = strprog.search(line) | ||
| 70 | + if match: | ||
| 71 | + lines.append(" '" + match.group(1) + "',\n") | ||
| 73 | 72 | lines.sort() | |
| 74 | 73 | ||
| 75 | 74 | # load the output skeleton from the target | |
| 76 | - fp = open(optfile) | ||
| 77 | - format = fp.readlines() | ||
| 78 | - fp.close() | ||
| 75 | + with open(optfile) as fp: | ||
| 76 | + format = fp.readlines() | ||
| 79 | 77 | ||
| 80 | 78 | # insert the lines of keywords | |
| 81 | 79 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,21 +155,15 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None): | |||
| 155 | 155 | if 'HOME' in os.environ: | |
| 156 | 156 | envHome = os.environ['HOME'] | |
| 157 | 157 | try: | |
| 158 | - rcFile = open(os.path.join(envHome, ".pdbrc")) | ||
| 158 | + with open(os.path.join(envHome, ".pdbrc")) as rcFile: | ||
| 159 | + self.rcLines.extend(rcFile) | ||
| 159 | 160 | except IOError: | |
| 160 | 161 | pass | |
| 161 | - else: | ||
| 162 | - for line in rcFile.readlines(): | ||
| 163 | - self.rcLines.append(line) | ||
| 164 | - rcFile.close() | ||
| 165 | 162 | try: | |
| 166 | - rcFile = open(".pdbrc") | ||
| 163 | + with open(".pdbrc") as rcFile: | ||
| 164 | + self.rcLines.extend(rcFile) | ||
| 167 | 165 | except IOError: | |
| 168 | 166 | pass | |
| 169 | - else: | ||
| 170 | - for line in rcFile.readlines(): | ||
| 171 | - self.rcLines.append(line) | ||
| 172 | - rcFile.close() | ||
| 173 | 167 | ||
| 174 | 168 | self.commands = {} # associates a command list to breakpoint numbers | |
| 175 | 169 | self.commands_doprompt = {} # for each bp num, tells if the prompt | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,9 +200,8 @@ def _dist_try_harder(distname,version,id): | |||
| 200 | 200 | """ | |
| 201 | 201 | if os.path.exists('/var/adm/inst-log/info'): | |
| 202 | 202 | # SuSE Linux stores distribution information in that file | |
| 203 | - info = open('/var/adm/inst-log/info').readlines() | ||
| 204 | 203 | distname = 'SuSE' | |
| 205 | - for line in info: | ||
| 204 | + for line in open('/var/adm/inst-log/info'): | ||
| 206 | 205 | tv = line.split() | |
| 207 | 206 | if len(tv) == 2: | |
| 208 | 207 | tag,value = tv | |
@@ -217,8 +216,7 @@ def _dist_try_harder(distname,version,id): | |||
| 217 | 216 | ||
| 218 | 217 | if os.path.exists('/etc/.installed'): | |
| 219 | 218 | # Caldera OpenLinux has some infos in that file (thanks to Colin Kong) | |
| 220 | - info = open('/etc/.installed').readlines() | ||
| 221 | - for line in info: | ||
| 219 | + for line in open('/etc/.installed'): | ||
| 222 | 220 | pkg = line.split('-') | |
| 223 | 221 | if len(pkg) >= 2 and pkg[0] == 'OpenLinux': | |
| 224 | 222 | # XXX does Caldera support non Intel platforms ? If yes, | |
@@ -327,9 +325,8 @@ def linux_distribution(distname='', version='', id='', | |||
| 327 | 325 | return _dist_try_harder(distname,version,id) | |
| 328 | 326 | ||
| 329 | 327 | # Read the first line | |
| 330 | - f = open('/etc/'+file, 'r') | ||
| 331 | - firstline = f.readline() | ||
| 332 | - f.close() | ||
| 328 | + with open('/etc/'+file, 'r') as f: | ||
| 329 | + firstline = f.readline() | ||
| 333 | 330 | _distname, _version, _id = _parse_release_file(firstline) | |
| 334 | 331 | ||
| 335 | 332 | if _distname and full_distribution_name: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,9 +169,8 @@ | |||
| 169 | 169 | ||
| 170 | 170 | def config_dict(filename): | |
| 171 | 171 | """Convert content of config-file into dictionary.""" | |
| 172 | - f = open(filename, "r") | ||
| 173 | - cfglines = f.readlines() | ||
| 174 | - f.close() | ||
| 172 | + with open(filename, "r") as f: | ||
| 173 | + cfglines = f.readlines() | ||
| 175 | 174 | cfgdict = {} | |
| 176 | 175 | for line in cfglines: | |
| 177 | 176 | line = line.strip() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments