/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/cmdline.py

  • Committer: Gordon Tyler
  • Date: 2010-02-02 05:24:08 UTC
  • mto: (5037.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5046.
  • Revision ID: gordon@doxxx.net-20100202052408-2zb777iauljocoys
Tweaked quote handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
                return None
48
48
            else:
49
49
                return self
50
 
        elif (next_char == u'"'
51
 
              or (context.single_quotes_allowed and next_char == u"'")):
 
50
        elif next_char in context.allowed_quote_chars:
52
51
            context.quoted = True
53
52
            return _Quotes(next_char, self)
54
53
        elif next_char == u'\\':
83
82
        if next_char == u'\\':
84
83
            self.count += 1
85
84
            return self
86
 
        elif next_char == u'"':
87
 
            # 2N backslashes followed by '"' are N backslashes
 
85
        elif next_char in context.allowed_quote_chars:
 
86
            # 2N backslashes followed by a quote are N backslashes
88
87
            context.token.append(u'\\' * (self.count/2))
89
 
            # 2N+1 backslashes follwed by '"' are N backslashes followed by '"'
90
 
            # which should not be processed as the start or end of quoted arg
 
88
            # 2N+1 backslashes follwed by a quote are N backslashes followed by
 
89
            # the quote which should not be processed as the start or end of
 
90
            # the quoted arg
91
91
            if self.count % 2 == 1:
92
 
                context.token.append(next_char) # odd number of '\' escapes the '"'
 
92
                # odd number of \ escapes the quote
 
93
                context.token.append(next_char)
93
94
            else:
94
 
                context.seq.pushback(next_char) # let exit_state handle next_char
 
95
                # let exit_state handle next_char
 
96
                context.seq.pushback(next_char)
95
97
            self.count = 0
96
98
            return self.exit_state
97
99
        else:
98
 
            # N backslashes not followed by '"' are just N backslashes
 
100
            # N backslashes not followed by a quote are just N backslashes
99
101
            if self.count > 0:
100
102
                context.token.append(u'\\' * self.count)
101
103
                self.count = 0
102
 
            context.seq.pushback(next_char) # let exit_state handle next_char
 
104
            # let exit_state handle next_char
 
105
            context.seq.pushback(next_char)
103
106
            return self.exit_state
104
107
    
105
108
    def finish(self, context):
111
114
    def process(self, next_char, context):
112
115
        if _whitespace_match(next_char):
113
116
            return None
114
 
        elif (next_char == u'"'
115
 
              or (context.single_quotes_allowed and next_char == u"'")):
 
117
        elif next_char in context.allowed_quote_chars:
116
118
            return _Quotes(next_char, self)
117
119
        elif next_char == u'\\':
118
120
            return _Backslash(self)
124
126
class Parser(object):
125
127
    def __init__(self, command_line, single_quotes_allowed=False):
126
128
        self.seq = _PushbackSequence(command_line)
127
 
        self.single_quotes_allowed = single_quotes_allowed
 
129
        self.allowed_quote_chars = u'"'
 
130
        if single_quotes_allowed:
 
131
            self.allowed_quote_chars += u"'"
128
132
    
129
133
    def __iter__(self):
130
134
        return self