Functions | |
def | quotedParse |
Variables | |
tuple | parser = OptionParser(usage="cmdline.py [options]") |
string | help = "Load given module and pass optional argument list" |
def DybPython::cmdline::quotedParse | ( | cmdstring | ) |
Take a the given command string and parse it into a list using space delimiters but respecting (one layer of) quotes.
Definition at line 3 of file cmdline.py.
00003 : 00004 '''Take a the given command string and parse it into a list using 00005 space delimiters but respecting (one layer of) quotes.''' 00006 00007 tokens = [] 00008 for arg in cmdstring.split(" "): 00009 if '' != arg: 00010 tokens.append(arg) 00011 pass 00012 continue 00013 00014 firsts = map(lambda x: x[0], tokens) 00015 lasts = map(lambda x: x[-1], tokens) 00016 00017 quoteIndex = -1 00018 quoteMark = None 00019 for f in firsts: 00020 quoteIndex += 1 00021 if f == '"' or f == "'": 00022 quoteMark = f 00023 break; 00024 continue 00025 00026 if quoteMark is None: 00027 return tokens 00028 00029 endIndex = 0 00030 endFound = None 00031 for l in lasts: 00032 endIndex += 1 00033 if l == quoteMark: 00034 endFound = True 00035 break 00036 continue 00037 00038 if not endFound: 00039 raise ValueError, "end quote not found" 00040 00041 return tokens[:quoteIndex] + [" ".join(tokens[quoteIndex:endIndex])[1:-1]] + tokens[endIndex:] 00042 if '__main__' == __name__:
tuple DybPython::cmdline::parser = OptionParser(usage="cmdline.py [options]") [static] |
Definition at line 48 of file cmdline.py.
string DybPython::cmdline::help = "Load given module and pass optional argument list" [static] |
Definition at line 50 of file cmdline.py.