<s> from __future__ import absolute_import , print_function , unicode_literals <EOL> from pkg_resources import parse_version <EOL> import requests <EOL> def fetch_package ( name ) : <EOL> r = requests . get ( "<STR_LIT>" . format ( name = name ) , timeout = <NUM_LIT:3> ) <EOL> if r . status_code != <NUM_LIT:200> : <EOL> return None <EOL> json = r . json ( ) <EOL> return Package ( <EOL> name , <EOL> sorted ( json [ "<STR_LIT>" ] . keys ( ) , key = lambda v : parse_version ( v ) , reverse = True ) <EOL> ) <EOL> class Package ( object ) : <EOL> def __init__ ( self , name , versions ) : <EOL> self . name = name <EOL> self . versions = versions <EOL> def latest_version ( self , prereleases = False ) : <EOL> for version in self . versions : <EOL> if prereleases or not parse_version ( version ) . is_prerelease : <EOL> return version <EOL> if self . versions and not prereleases : <EOL> return self . latest_version ( prereleases = True ) <EOL> return None </s>
