Skip to content

Commit

Permalink
#253 Ensure that opened files are closed
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
rakesh balusa authored and pombredanne committed Dec 6, 2016
1 parent 0d4905b commit a58ca53
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,20 @@ def parse_pkg_info(location):
parse a 'PKG-INFO' file at 'location' and return a PythonPackage object.
"""
infos = {}
with open(location, 'rb') as txt_file:
lines = []
for line in txt_file:
lines.append(line)
lines = ''.join(lines)
for attribute in PKG_INFO_ATTRIBUTES:
infos[attribute] = re.findall('^'+attribute+'[\s:]*.*', lines, flags=re.MULTILINE)[0]
infos[attribute] = re.sub('^'+attribute+'[\s:]*', '', infos[attribute], flags=re.MULTILINE)
if infos[attribute] == 'UNKNOWN':
infos[attribute] = None
package = PythonPackage(
name=infos.get('Name'),
version=infos.get('Version'),
summary=infos.get('Summary'),
homepage_url=infos.get('Home-page'),
asserted_licenses=[AssertedLicense(license=infos.get('License'))],
authors=[infos.get('Author')],
)
file_text = open(location, 'rb').read()
for attribute in PKG_INFO_ATTRIBUTES:
infos[attribute] = re.findall('^'+attribute+'[\s:]*.*', file_text, flags=re.MULTILINE)[0]
infos[attribute] = re.sub('^'+attribute+'[\s:]*', '', infos[attribute], flags=re.MULTILINE)
if infos[attribute] == 'UNKNOWN':
infos[attribute] = None
package = PythonPackage(
name=infos.get('Name'),
version=infos.get('Version'),
summary=infos.get('Summary'),
homepage_url=infos.get('Home-page'),
asserted_licenses=[AssertedLicense(license=infos.get('License'))],
authors=[infos.get('Author')],
)
return package


Expand Down

0 comments on commit a58ca53

Please sign in to comment.