# 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

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)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    elif op1 == "<":
        if v1:
            x = lower(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
            x = lower(list, x, pkg_comp_name)
    elif op1 == ">":
        if v1:
            x = higher(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = None
    elif op1 == "<=":
        if v1:
            x = floor(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name) #lower than last
    elif op1 == ">=":
        if v1:
            x = ceiling(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    else:

# 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


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)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    elif op1 == "<":
        if v1:
            x = lower(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
            x = lower(list, x, pkg_comp_name)
    elif op1 == ">":
        if v1:
            x = higher(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = None
    elif op1 == "<=":
        if v1:
            x = floor(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name) #lower than last
    elif op1 == ">=":
        if v1:
            x = ceiling(list, Package(pkg_name, complete_version(v1)), pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    else:

        raise InvalidParameter("Invalid operator" + op1)