Exemplo n.º 1
0
def parse_scalesize_xml(elem):
    """ Parses the XML notation of a single scale size.
    """

    axis = elem.findtext(ns_scal("axis"))
    if axis not in all_axes:
        raise ScaleAxisUndefinedException(axis)
    try:
        raw = elem.findtext(ns_scal("targetSize"))
        value = int(raw)
    except ValueError:
        InvalidScaleFactorException(raw)

    return ScaleSize(axis, value)
Exemplo n.º 2
0
def parse_scalesize_kvp(string):
    """ Parses the KVP notation of a single scale size.
    """

    match = SCALESIZE_RE.match(string)
    if not match:
        raise Exception("Could not parse input scale size string.")

    axis = match.group(1)
    if axis not in all_axes:
        raise ScaleAxisUndefinedException(axis)
    try:
        value = int(match.group(2))
    except ValueError:
        raise InvalidScaleFactorException(match.group(2))

    return ScaleSize(axis, value)
Exemplo n.º 3
0
def parse_scaleextent_xml(elem):
    """ Parses the XML notation of a single scale extent.
    """

    axis = elem.findtext(ns_scal("axis"))
    if axis not in all_axes:
        raise ScaleAxisUndefinedException(axis)
    try:
        raw_low = elem.findtext(ns_scal("low"))
        raw_high = elem.findtext(ns_scal("high"))
        low = int(raw_low)
        high = int(raw_high)
    except ValueError:
        InvalidScaleFactorException(raw_high)

    if low >= high:
        raise InvalidScaleExtentException(low, high)

    return ScaleExtent(axis, low, high)
Exemplo n.º 4
0
def parse_scaleextent_kvp(string):
    """ Parses the KVP notation of a single scale extent.
    """

    match = SCALEEXTENT_RE.match(string)
    if not match:
        raise Exception("Could not parse input scale extent string.")

    axis = match.group(1)
    if axis not in all_axes:
        raise ScaleAxisUndefinedException(axis)
    try:
        low = int(match.group(2))
        high = int(match.group(3))
    except ValueError:
        raise InvalidScaleFactorException(match.group(3))

    if low >= high:
        raise InvalidScaleExtentException(low, high)

    return ScaleExtent(axis, low, high)