return self._valid
def parse(self):
- lines = io.open(_unicode_encode(self.path,
+ f = io.open(_unicode_encode(self.path,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['content'], errors='replace'
- ).readlines()
+ mode='r', encoding=_encodings['content'], errors='replace')
+ lines = f.readlines()
+ f.close()
self.restrictions = {}
invalids = []
for i, line in enumerate(lines):
if token[0] in quotes and token[0] == token[-1]:
token = token[1:-1]
return token
+
+ f = None
try:
- lineno=0
- for line in io.open(_unicode_encode(myfile,
+ f = io.open(_unicode_encode(myfile,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['content'], errors='replace'):
+ mode='r', encoding=_encodings['content'], errors='replace')
+ lineno = 0
+ for line in f:
lineno += 1
commenter_pos = line.find("#")
elif e.errno == errno.EACCES:
raise PermissionDenied(myfile)
raise
+ finally:
+ if f is not None:
+ f.close()
def nc_len(mystr):
tmp = re.sub(esc_seq + "^m]+m", "", mystr);
def _addProfile(self, currentPath):
parentsFile = os.path.join(currentPath, "parent")
eapi_file = os.path.join(currentPath, "eapi")
+ f = None
try:
- eapi = io.open(_unicode_encode(eapi_file,
+ f = io.open(_unicode_encode(eapi_file,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['content'], errors='replace'
- ).readline().strip()
+ mode='r', encoding=_encodings['content'], errors='replace')
+ eapi = f.readline().strip()
except IOError:
pass
else:
"Profile contains unsupported "
"EAPI '%s': '%s'") % \
(eapi, os.path.realpath(eapi_file),))
+ finally:
+ if f is not None:
+ f.close()
if os.path.exists(parentsFile):
parents = grabfile(parentsFile)
if not parents:
Returns repo_name, missing.
"""
repo_name_path = os.path.join(repo_path, REPO_NAME_LOC)
+ f = None
try:
- return io.open(
+ f = io.open(
_unicode_encode(repo_name_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
- errors='replace').readline().strip(), False
+ errors='replace')
+ return f.readline().strip(), False
except EnvironmentError:
return "x-" + os.path.basename(repo_path), True
+ finally:
+ if f is not None:
+ f.close()
def info_string(self):
"""
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage import os
os.makedirs(settings[x])
# Create a fake environment, to pretend as if the ebuild
# has been sourced already.
- open(os.path.join(settings['T'], 'environment'), 'wb')
+ open(os.path.join(settings['T'], 'environment'), 'wb').close()
scheduler = PollScheduler().sched_iface
for phase in ('_internal_test',):
else:
expand_map = {}
mykeys = {}
+ f = None
try:
# NOTE: shlex doesn't support unicode objects with Python 2
# (produces spurious \0 characters).
if sys.hexversion < 0x3000000:
- content = open(_unicode_encode(mycfg,
- encoding=_encodings['fs'], errors='strict'), 'rb').read()
+ f = open(_unicode_encode(mycfg,
+ encoding=_encodings['fs'], errors='strict'), 'rb')
else:
- content = open(_unicode_encode(mycfg,
+ f = open(_unicode_encode(mycfg,
encoding=_encodings['fs'], errors='strict'), mode='r',
- encoding=_encodings['content'], errors='replace').read()
+ encoding=_encodings['content'], errors='replace')
+ content = f.read()
except IOError as e:
if e.errno == PermissionDenied.errno:
raise PermissionDenied(mycfg)
if e.errno not in (errno.EISDIR,):
raise
return None
+ finally:
+ if f is not None:
+ f.close()
# Workaround for avoiding a silent error in shlex that is
# triggered by a source statement at the end of the file