<s> from collections import defaultdict <EOL> from . platforms import PLATFORMS <EOL> SUPPORTED_ATTRIBUTES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:port>' , <EOL> '<STR_LIT:url>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def parse ( url , check_domain = True ) : <EOL> parsed_info = defaultdict ( lambda : None ) <EOL> parsed_info [ '<STR_LIT:port>' ] = '<STR_LIT>' <EOL> map ( parsed_info . setdefault , SUPPORTED_ATTRIBUTES ) <EOL> for name , platform in PLATFORMS : <EOL> for protocol , regex in platform . COMPILED_PATTERNS . items ( ) : <EOL> match = regex . match ( url ) <EOL> if not match : <EOL> continue <EOL> domain = match . group ( '<STR_LIT>' ) <EOL> if check_domain : <EOL> if platform . DOMAINS and not ( domain in platform . DOMAINS ) : <EOL> continue <EOL> matches = match . groupdict ( ) <EOL> parsed_info . update ( matches ) <EOL> parsed_info . update ( platform . DEFAULTS ) <EOL> parsed_info . update ( { <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : name , <EOL> '<STR_LIT>' : protocol , <EOL> } ) <EOL> return parsed_info <EOL> return parsed_info </s>
