+ def parse_yx_tuple(self, yx_string, range_=None):
+ """Parse yx_string as yx_tuple, return result.
+
+ The range_ argument may be 'nonneg' (non-negative, including
+ 0) or 'pos' (positive, excluding 0).
+
+ """
+
+ def get_axis_position_from_argument(axis, token):
+ if len(token) < 3 or token[:2] != axis + ':' or \
+ not (token[2:].isdigit() or token[2] == '-'):
+ raise ArgError('Non-int arg for ' + axis + ' position.')
+ n = int(token[2:])
+ if n < 1 and range_ == 'pos':
+ raise ArgError('Arg for ' + axis + ' position < 1.')
+ elif n < 0 and range_ == 'nonneg':
+ raise ArgError('Arg for ' + axis + ' position < 0.')
+ return n
+
+ tokens = yx_string.split(',')
+ if len(tokens) != 2:
+ raise ArgError('Wrong number of yx-tuple arguments.')
+ y = get_axis_position_from_argument('Y', tokens[0])
+ x = get_axis_position_from_argument('X', tokens[1])
+ return YX(y, x)
+