# Path: ethronsoft/gcspypi/utilities/version.py
# def complete_version(v):
#     """adds missing '0' to a version that has less than 3 components
#     
#     Arguments:
#         v {str} -- The version to update
#     
#     Returns:
#         str -- The modified version
#     """
# 
#     tokens = [x for x in v.split(".") if x.strip()]
#     if len(tokens) > 3:
#         raise InvalidParameter("Invalid Version")
#     for i in range(3 - len(tokens)):
#         tokens.append("0")
#     return ".".join(tokens)
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class InvalidParameter(Exception):
#     pass


from ethronsoft.gcspypi.utilities.version import complete_version
from ethronsoft.gcspypi.exceptions import InvalidParameter
    from ethronsoft.gcspypi.package.package import Package
    from ethronsoft.gcspypi.package.package import Package
import functools
    # c = cmp(list[indx], key)
    # if c < 0:
    #     return list[indx]
    # else:
    return list[indx - 1] if indx > 0 else None


def higher(list, key, cmp=cmp):
    if not list: return None
    indx = cmp_bisect(list, key, cmp)
    if indx >= len(list):
        return None
    c = cmp(list[indx], key)
    if c <= 0:
        return list[indx + 1] if indx < len(list) - 1 else None
    else:
        return list[indx]


def equal(list, key, cmp=cmp):
    if not list: return None
    indx = cmp_bisect(list, key, cmp)
    if indx >= len(list): return None
    return list[indx] if cmp(list[indx], key) == 0 else None


def pkg_range_query(list, pkg_name, op1="", v1="", op2="", v2=""):
    # empty version means last version
    if op1 == "==" or not op1:
        if v1:

# Path: ethronsoft/gcspypi/utilities/version.py
# def complete_version(v):
#     """adds missing '0' to a version that has less than 3 components
#     
#     Arguments:
#         v {str} -- The version to update
#     
#     Returns:
#         str -- The modified version
#     """
# 
#     tokens = [x for x in v.split(".") if x.strip()]
#     if len(tokens) > 3:
#         raise InvalidParameter("Invalid Version")
#     for i in range(3 - len(tokens)):
#         tokens.append("0")
#     return ".".join(tokens)
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class InvalidParameter(Exception):
#     pass


# Path: ethronsoft/gcspypi/utilities/queries.py
from ethronsoft.gcspypi.utilities.version import complete_version
from ethronsoft.gcspypi.exceptions import InvalidParameter
    from ethronsoft.gcspypi.package.package import Package
    from ethronsoft.gcspypi.package.package import Package
import functools

    # c = cmp(list[indx], key)
    # if c < 0:
    #     return list[indx]
    # else:
    return list[indx - 1] if indx > 0 else None


def higher(list, key, cmp=cmp):
    if not list: return None
    indx = cmp_bisect(list, key, cmp)
    if indx >= len(list):
        return None
    c = cmp(list[indx], key)
    if c <= 0:
        return list[indx + 1] if indx < len(list) - 1 else None
    else:
        return list[indx]


def equal(list, key, cmp=cmp):
    if not list: return None
    indx = cmp_bisect(list, key, cmp)
    if indx >= len(list): return None
    return list[indx] if cmp(list[indx], key) == 0 else None


def pkg_range_query(list, pkg_name, op1="", v1="", op2="", v2=""):
    # empty version means last version
    if op1 == "==" or not op1:
        if v1:

            x = equal(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)