<s> """<STR_LIT>""" <EOL> try : <EOL> from shlex import quote as shell_quote <EOL> except ImportError : <EOL> from pipes import quote as shell_quote <EOL> import subprocess <EOL> def discrete_ranges ( values , succ = lambda x : x + <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> ranges = [ ] <EOL> last = None <EOL> for x in sorted ( values ) : <EOL> if last is None : <EOL> start = last = x <EOL> else : <EOL> if x == succ ( last ) : <EOL> last = x <EOL> else : <EOL> ranges . append ( ( start , last ) ) <EOL> last = None <EOL> if last is not None : <EOL> ranges . append ( ( start , last ) ) <EOL> return ranges <EOL> def shell ( prog , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> cmd_parts = [ prog ] <EOL> cmd_parts . extend ( map ( shell_quote , args ) ) <EOL> for flag , value in kwargs . iteritems ( ) : <EOL> prefix = '<STR_LIT:->' if len ( flag ) == <NUM_LIT:1> else '<STR_LIT>' <EOL> cmd_parts . append ( ( prefix + flag . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) ) ) <EOL> if value and value is not True : <EOL> cmd_parts . append ( shell_quote ( value ) ) <EOL> cmd = '<STR_LIT:U+0020>' . join ( cmd_parts ) <EOL> process = subprocess . Popen ( cmd , shell = True , stdout = subprocess . PIPE ) <EOL> out , _ = process . communicate ( ) <EOL> return out </s>
