Skip to content

Commit

Permalink
renaming *license* variables into *license*
Browse files Browse the repository at this point in the history
attempt to fix #124 as per wpoa/recitation-bot@b6ce76b
  • Loading branch information
Daniel-Mietchen committed Nov 28, 2014
1 parent 2ff00b3 commit f42313c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions sources/pmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,67 +481,67 @@ def _get_article_licensing(tree):
"""
Given an ElementTree, returns article license URL.
"""
license_text = None
license_url = None
licence_text = None
licence_url = None
copyright_statement_text = None

license = tree.find('front//*license')
licence = tree.find('front//*license')
copyright_statement = tree.find('front//*copyright-statement')

def _get_text_from_element(element):
text = ' '.join(element.itertext()).encode('utf-8') # clean encoding
text = ' '.join(text.split()) # clean whitespace
return text

if license is not None:
if licence is not None:
try:
license_url = license.attrib['{http://www.w3.org/1999/xlink}href']
except KeyError: # license URL is possibly in <ext-link> element
licence_url = licence.attrib['{http://www.w3.org/1999/xlink}href']
except KeyError: # licence URL is possibly in in <ext-link> element
try:
ext_link = license.find('license-p/ext-link')
ext_link = licence.find('license-p/ext-link')
if ext_link is not None:
license_url = \
licence_url = \
ext_link.attrib['{http://www.w3.org/1999/xlink}href']
except KeyError: # license statement is in plain text
license_text = _get_text_from_element(license)
except KeyError: # licence statement is in plain text
licence_text = _get_text_from_element(licence)
elif copyright_statement is not None:
copyright_statement_text = _get_text_from_element(copyright_statement)
else:
logging.error('No <license> or <copyright-statement> element found in XML.')
return None, None, None

if license_url is None:
if license_text is not None:
if licence_url is None:
if licence_text is not None:
try:
license_url = license_url_equivalents[license_text]
licence_url = licence_url_equivalents[licence_text]
except:
logging.error('Unknown license: %s', license_text)
logging.error('Unknown license: %s', licence_text)

elif copyright_statement_text is not None:
copyright_statement_found = False
for text in copyright_statement_url_equivalents.keys():
if copyright_statement_text.endswith(text):
license_url = copyright_statement_url_equivalents[text]
licence_url = copyright_statement_url_equivalents[text]
copyright_statement_found = True
break
if not copyright_statement_found:
logging.error('Unknown copyright statement: %s', copyright_statement_text)

def _fix_license_url(license_url):
if license_url in license_url_fixes.keys():
return license_url_fixes[license_url]
return license_url
def _fix_licence_url(licence_url):
if licence_url in licence_url_fixes.keys():
return licence_url_fixes[licence_url]
return licence_url

if license_text is not None:
license_text = license_text.decode('utf-8')
if licence_text is not None:
licence_text = licence_text.decode('utf-8')

if copyright_statement_text is not None:
copyright_statement_text = copyright_statement_text.decode('utf-8')

if license_url is not None:
return _fix_license_url(license_url), license_text, copyright_statement_text
if licence_url is not None:
return _fix_licence_url(licence_url), licence_text, copyright_statement_text
else:
return None, license_text, copyright_statement_text
return None, licence_text, copyright_statement_text

def _get_article_copyright_holder(tree):
"""
Expand Down

1 comment on commit f42313c

@Daniel-Mietchen
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit title should have been "renaming license variables into licence".

Please sign in to comment.