def get_version_and_release_date(requirement, version=None,<EOL>verbose=False, response=None):
try:<EOL><INDENT>if not response:<EOL><INDENT>url = get_pypi_url(requirement, version)<EOL>response = requests.get(url)<EOL><DEDENT>if response.status_code == <NUM_LIT>:<EOL><INDENT>root_url = url.rpartition('<STR_LIT:/>')[<NUM_LIT:0>]<EOL>res = requests.head(root_url)<EOL>if res.status_code == <NUM_LIT>:<EOL><INDENT>new_location = res.headers['<STR_LIT:location>'] + '<STR_LIT>'<EOL>response = requests.get(new_location)<EOL><DEDENT><DEDENT>response = response.json()<EOL><DEDENT>except requests.HTTPError:<EOL><INDENT>if version:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>'.format(requirement, version))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>'.format(requirement))<EOL><DEDENT><DEDENT>return None, None<EOL><DEDENT>except ValueError:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>'.format(requirement, version))<EOL><DEDENT>return None, None<EOL><DEDENT>try:<EOL><INDENT>if version:<EOL><INDENT>if version in response['<STR_LIT>']:<EOL><INDENT>release_date = response['<STR_LIT>'][version][<NUM_LIT:0>]['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>return None, None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>version = response['<STR_LIT:info>'].get('<STR_LIT>')<EOL>if not version:<EOL><INDENT>versions = {<EOL>v: parse_version(v) for v in response['<STR_LIT>'].keys()<EOL>if not parse_version(v).is_prerelease()<EOL>}<EOL>if not versions:<EOL><INDENT>versions = {<EOL>v: parse_version(v) for v in response['<STR_LIT>'].keys()<EOL>}<EOL><DEDENT>if versions:<EOL><INDENT>version = max(versions.items(), key=operator.itemgetter(<NUM_LIT:1>))[<NUM_LIT:0>]<EOL>release_date = (<EOL>response['<STR_LIT>'][str(version)][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return None, None<EOL><DEDENT><DEDENT><DEDENT>return version, datetime.fromtimestamp(time.mktime(<EOL>time.strptime(release_date, '<STR_LIT>')<EOL>))<EOL><DEDENT>except IndexError:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(requirement,<EOL>version))<EOL><DEDENT>return None, None<EOL><DEDENT>
Given a requirement and optional version returns a (version, releasedate)
    tuple. Defaults to the latest version. Prints to stdout if verbose is True.
    Optional response argument is the response from PyPI to be used for
    asyncronous lookups.