@@ -36,38 +36,36 @@ def run_pirate_commands(self, command_string):
3636 _CHARS_VALID_IN_NUMBER = "0123456789abcdefxh"
3737
3838
39- result = []
40- commands = list (command_string )
39+ self . _result = []
40+ self . _commands = list (command_string )
4141
4242 # Simple performance enhancement: we'll gather any consecutive reads/writes and issue
4343 # them as single commands to the GreatFET.
44- pending_write_data = []
45- pending_read_length = 0
44+ self . _pending_write_data = []
45+ self . _pending_read_length = 0
4646
4747
4848 def issue_pending_writes (ends_transaction = False ):
4949 """ Issues any writes pending; used when performing a non-write operation."""
50- nonlocal pending_write_data , result
5150
52- if not pending_write_data :
51+ if not self . _pending_write_data :
5352 return
5453
5554 # Perform all of our pending writes.
56- result . extend (self ._handle_pirate_write (pending_write_data , ends_transaction = ends_transaction ))
57- pending_write_data = []
55+ self . _result . extend (self ._handle_pirate_write (self . _pending_write_data , ends_transaction = ends_transaction ))
56+ self . _pending_write_data = []
5857
5958
6059 def perform_pending_reads (ends_transaction = False ):
6160 """ Issues any writes pending; used when performing a non-write operation."""
62- nonlocal pending_read_length , result
6361
6462 # If we don't have any pending reads, don't do anything.
65- if not pending_read_length :
63+ if not self . _pending_read_length :
6664 return
6765
6866 # Perform all of our pending reads.
69- result . extend (self ._handle_pirate_read (pending_read_length , ends_transaction = ends_transaction ))
70- pending_read_length = 0
67+ self . _result . extend (self ._handle_pirate_read (self . _pending_read_length , ends_transaction = ends_transaction ))
68+ self . _pending_read_length = 0
7169
7270
7371 def handle_pending_io (ends_transaction = False ):
@@ -83,16 +81,14 @@ def extract_number(char=None):
8381 starts with a number.
8482 """
8583
86- nonlocal commands
87-
8884 # Start building our number.
8985 number = []
9086
9187 try :
9288
9389 # If we don't have a starting character, read one.
9490 if char is None :
95- char = commands .pop (0 )
91+ char = self . _commands .pop (0 )
9692
9793 # Grab all characters from the string until we run out of numbers.
9894 while char in _CHARS_VALID_IN_NUMBER :
@@ -102,7 +98,7 @@ def extract_number(char=None):
10298 char = 'x' if (char == 'h' ) else char
10399
104100 number .append (char )
105- char = commands .pop (0 )
101+ char = self . _commands .pop (0 )
106102
107103
108104
@@ -128,12 +124,11 @@ def get_repeat_count():
128124 If it doesn't, returns a default value of 1.
129125
130126 """
131- nonlocal commands
132127
133- if len (commands ) and commands [0 ] == ':' :
128+ if len (self . _commands ) and self . _commands [0 ] == ':' :
134129
135130 # Discard our colon...
136- del commands [0 ]
131+ del self . _commands [0 ]
137132
138133 # ... and extract the relevant number.
139134 return extract_number ()
@@ -143,13 +138,13 @@ def get_repeat_count():
143138
144139
145140 # Handle each byte in the command string.
146- while commands :
141+ while self . _commands :
147142
148143 # Start off with no repeat modifier, and no pending operation.
149144 length = None
150145
151146 # Grab the next command-character in the queue.
152- char = commands .pop (0 )
147+ char = self . _commands .pop (0 )
153148
154149 # If this character starts a number, we have a write operation.
155150 if char in _CHARS_VALID_TO_START_NUMBER :
@@ -160,7 +155,7 @@ def get_repeat_count():
160155
161156 # Schedule the write.
162157 perform_pending_reads ()
163- pending_write_data .append (byte )
158+ self . _pending_write_data .append (byte )
164159
165160 # Handle our core commands.
166161 elif char in _START_CHARS :
@@ -175,7 +170,7 @@ def get_repeat_count():
175170 issue_pending_writes ()
176171
177172 length = get_repeat_count ()
178- pending_read_length += length
173+ self . _pending_read_length += length
179174
180175 elif char in _DELAY_CHARS :
181176 handle_pending_io ()
@@ -193,7 +188,7 @@ def get_repeat_count():
193188 # TODO: support 'D/d'?
194189 # TODO: message on 'Ww'?
195190
196- return result
191+ return self . _result
197192
198193
199194 #
0 commit comments