<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pants . base . specs import DescendantAddresses , SiblingAddresses , SingleAddress <EOL> class CmdLineSpecParser ( object ) : <EOL> """<STR_LIT>""" <EOL> class BadSpecError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root_dir ) : <EOL> self . _root_dir = os . path . realpath ( root_dir ) <EOL> def _normalize_spec_path ( self , path ) : <EOL> is_abs = not path . startswith ( '<STR_LIT>' ) and os . path . isabs ( path ) <EOL> if is_abs : <EOL> path = os . path . realpath ( path ) <EOL> if os . path . commonprefix ( [ self . _root_dir , path ] ) != self . _root_dir : <EOL> raise self . BadSpecError ( '<STR_LIT>' <EOL> . format ( path , self . _root_dir ) ) <EOL> else : <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> path = path [ <NUM_LIT:2> : ] <EOL> path = os . path . join ( self . _root_dir , path ) <EOL> normalized = os . path . relpath ( path , self . _root_dir ) <EOL> if normalized == '<STR_LIT:.>' : <EOL> normalized = '<STR_LIT>' <EOL> return normalized <EOL> def parse_spec ( self , spec ) : <EOL> """<STR_LIT>""" <EOL> if spec . endswith ( '<STR_LIT>' ) : <EOL> spec_path = spec [ : - len ( '<STR_LIT>' ) ] <EOL> return DescendantAddresses ( self . _normalize_spec_path ( spec_path ) ) <EOL> elif spec . endswith ( '<STR_LIT::>' ) : <EOL> spec_path = spec [ : - len ( '<STR_LIT::>' ) ] <EOL> return SiblingAddresses ( self . _normalize_spec_path ( spec_path ) ) <EOL> else : <EOL> spec_parts = spec . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> return SingleAddress ( self . _normalize_spec_path ( spec_parts [ <NUM_LIT:0> ] ) , <EOL> spec_parts [ <NUM_LIT:1> ] if len ( spec_parts ) > <NUM_LIT:1> else None ) </s>
