~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cmdline.py

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010-2011 Canonical Ltd
 
1
# Copyright (C) 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Unicode-compatible command-line splitter for all platforms.
18
 
 
19
 
The user-visible behaviour of this module is described in
20
 
configuring_bazaar.txt.
21
 
"""
 
17
"""Unicode-compatible command-line splitter for all platforms."""
22
18
 
23
19
import re
24
20
 
30
26
    def __init__(self, orig):
31
27
        self._iter = iter(orig)
32
28
        self._pushback_buffer = []
33
 
 
 
29
        
34
30
    def next(self):
35
31
        if len(self._pushback_buffer) > 0:
36
32
            return self._pushback_buffer.pop()
37
33
        else:
38
34
            return self._iter.next()
39
 
 
 
35
    
40
36
    def pushback(self, char):
41
37
        self._pushback_buffer.append(char)
42
 
 
 
38
        
43
39
    def __iter__(self):
44
40
        return self
45
41
 
81
77
    def __init__(self, exit_state):
82
78
        self.exit_state = exit_state
83
79
        self.count = 1
84
 
 
 
80
        
85
81
    def process(self, next_char, context):
86
82
        if next_char == u'\\':
87
83
            self.count += 1
108
104
            # let exit_state handle next_char
109
105
            context.seq.pushback(next_char)
110
106
            return self.exit_state
111
 
 
 
107
    
112
108
    def finish(self, context):
113
109
        if self.count > 0:
114
110
            context.token.append(u'\\' * self.count)
133
129
        self.allowed_quote_chars = u'"'
134
130
        if single_quotes_allowed:
135
131
            self.allowed_quote_chars += u"'"
136
 
 
 
132
    
137
133
    def __iter__(self):
138
134
        return self
139
 
 
 
135
    
140
136
    def next(self):
141
137
        quoted, token = self._get_token()
142
138
        if token is None:
143
139
            raise StopIteration
144
140
        return quoted, token
145
 
 
 
141
    
146
142
    def _get_token(self):
147
143
        self.quoted = False
148
144
        self.token = []