# Path: libxyz/core/utils.py
# def bstring(bstr, enc=None):
#     """
#     Return encoded byte string
#     """
# 
#     if isinstance(bstr, str):
#         return bstr
#     
#     if enc is None:
#         enc = xyzenc
# 
#     if not isinstance(bstr, unicode):
#         return str(bstr)
# 
#     return bstr.encode(enc, 'replace')


import os
import itertools
from libxyz.core.utils import bstring
from domain_base import BaseDomain




class Domain(BaseDomain):
    """
    Bin path domain
    """

    def prepare(self):
        """
        Preparation stuff
        """

        path = os.getenv("PATH", "")

        for d in path.split(":"):
            self._update(d)

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def complete(self, buf):
        """
        Take current buffer and return list-generator of all
                matched entries in current domain.

        @param buf: Current buffer
        @return: list-generator
        """


# Path: libxyz/core/utils.py
# def bstring(bstr, enc=None):
#     """
#     Return encoded byte string
#     """
# 
#     if isinstance(bstr, str):
#         return bstr
#     
#     if enc is None:
#         enc = xyzenc
# 
#     if not isinstance(bstr, unicode):
#         return str(bstr)
# 
#     return bstr.encode(enc, 'replace')


# Path: plugins/core/complete/domain_binpath.py
import os
import itertools
from libxyz.core.utils import bstring
from domain_base import BaseDomain





class Domain(BaseDomain):
    """
    Bin path domain
    """

    def prepare(self):
        """
        Preparation stuff
        """

        path = os.getenv("PATH", "")

        for d in path.split(":"):
            self._update(d)

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def complete(self, buf):
        """
        Take current buffer and return list-generator of all
                matched entries in current domain.

        @param buf: Current buffer
        @return: list-generator
        """


        return itertools.ifilter(lambda x: x.startswith(bstring(buf)),