def parse_geometry(geometry, ratio=None):
m = geometry_pat.match(geometry)<EOL>def syntax_error():<EOL><INDENT>return ThumbnailParseError('<STR_LIT>'<EOL>'<STR_LIT>' % geometry)<EOL><DEDENT>if not m:<EOL><INDENT>raise syntax_error()<EOL><DEDENT>x = m.group('<STR_LIT:x>')<EOL>y = m.group('<STR_LIT:y>')<EOL>if x is None and y is None:<EOL><INDENT>raise syntax_error()<EOL><DEDENT>if x is not None:<EOL><INDENT>x = int(x)<EOL><DEDENT>if y is not None:<EOL><INDENT>y = int(y)<EOL><DEDENT>if ratio is not None:<EOL><INDENT>ratio = float(ratio)<EOL>if x is None:<EOL><INDENT>x = toint(y * ratio)<EOL><DEDENT>elif y is None:<EOL><INDENT>y = toint(x / ratio)<EOL><DEDENT><DEDENT>return x, y<EOL>
Parses a geometry string syntax and returns a (width, height) tuple