# Path: ubelt/util_mixins.py
# class NiceRepr(object):
#     """
#     Inherit from this class and define ``__nice__`` to "nicely" print your
#     objects.
# 
#     Defines ``__str__`` and ``__repr__`` in terms of ``__nice__`` function
#     Classes that inherit from :class:`NiceRepr` should redefine ``__nice__``.
#     If the inheriting class has a ``__len__``, method then the default
#     ``__nice__`` method will return its length.
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Foo(ub.NiceRepr):
#         ...    def __nice__(self):
#         ...        return 'info'
#         >>> foo = Foo()
#         >>> assert str(foo) == '<Foo(info)>'
#         >>> assert repr(foo).startswith('<Foo(info) at ')
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Bar(ub.NiceRepr):
#         ...    pass
#         >>> bar = Bar()
#         >>> import pytest
#         >>> with pytest.warns(RuntimeWarning) as record:
#         >>>     assert 'object at' in str(bar)
#         >>>     assert 'object at' in repr(bar)
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Baz(ub.NiceRepr):
#         ...    def __len__(self):
#         ...        return 5
#         >>> baz = Baz()
#         >>> assert str(baz) == '<Baz(5)>'
# 
#     Example:
#         >>> import ubelt as ub
#         >>> # If your nice message has a bug, it shouldn't bring down the house
#         >>> class Foo(ub.NiceRepr):
#         ...    def __nice__(self):
#         ...        assert False
#         >>> foo = Foo()
#         >>> import pytest
#         >>> with pytest.warns(RuntimeWarning) as record:
#         >>>     print('foo = {!r}'.format(foo))
#         foo = <...Foo ...>
#     """
# 
#     def __nice__(self):
#         if hasattr(self, '__len__'):
#             # It is a common pattern for objects to use __len__ in __nice__
#             # As a convenience we define a default __nice__ for these objects
#             return str(len(self))
#         else:
#             # In all other cases force the subclass to overload __nice__
#             raise NotImplementedError(
#                 'Define the __nice__ method for {!r}'.format(self.__class__))
# 
#     def __repr__(self):
#         try:
#             nice = self.__nice__()
#             classname = self.__class__.__name__
#             return '<{0}({1}) at {2}>'.format(classname, nice, hex(id(self)))
#         except Exception as ex:
#             warnings.warn(str(ex), category=RuntimeWarning)
#             return object.__repr__(self)
# 
#     def __str__(self):
#         try:
#             classname = self.__class__.__name__
#             nice = self.__nice__()
#             return '<{0}({1})>'.format(classname, nice)
#         except Exception as ex:
#             warnings.warn(str(ex), category=RuntimeWarning)
#             return object.__repr__(self)


import io
import os
    import re
            import zipfile
            import ubelt as ub
                import tempfile
from os.path import exists, join
from ubelt.util_mixins import NiceRepr
        >>> split_archive('/a/b/foo.zip/baz.pt/bar.zip/bar.zip', '.pt')

    TODO:
        Fix got/want for win32

        (None, None)
        ('/a/b/foo.zip', 'bar.txt')
        ('/a/b/foo.zip/baz/biz.zip', 'bar.py')
        ('archive.zip', None)
        ('/a/b/foo.zip/baz/biz.zip', 'bar.py')
        ('/a/b/foo.zip/baz.pt', 'bar.zip/bar.zip')
    """
    fpath = os.fspath(fpath)
    # fpath = os.fspath(fpath)
    pat = '({}[{}/:])'.format(re.escape(ext), re.escape(os.path.sep))
    # pat = r'(\'' + ext + '[' + re.escape(os.path.sep) + '/:])'
    parts = re.split(pat, fpath, flags=re.IGNORECASE)
    if len(parts) > 2:
        archivepath = ''.join(parts[:-1])[:-1]
        internal = parts[-1]
    elif len(parts) == 1:
        archivepath = parts[0]
        if not archivepath.endswith(ext):
            archivepath = None
        internal = None
    else:  # nocover
        raise AssertionError('impossible state')
    return archivepath, internal



# Path: ubelt/util_mixins.py
# class NiceRepr(object):
#     """
#     Inherit from this class and define ``__nice__`` to "nicely" print your
#     objects.
# 
#     Defines ``__str__`` and ``__repr__`` in terms of ``__nice__`` function
#     Classes that inherit from :class:`NiceRepr` should redefine ``__nice__``.
#     If the inheriting class has a ``__len__``, method then the default
#     ``__nice__`` method will return its length.
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Foo(ub.NiceRepr):
#         ...    def __nice__(self):
#         ...        return 'info'
#         >>> foo = Foo()
#         >>> assert str(foo) == '<Foo(info)>'
#         >>> assert repr(foo).startswith('<Foo(info) at ')
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Bar(ub.NiceRepr):
#         ...    pass
#         >>> bar = Bar()
#         >>> import pytest
#         >>> with pytest.warns(RuntimeWarning) as record:
#         >>>     assert 'object at' in str(bar)
#         >>>     assert 'object at' in repr(bar)
# 
#     Example:
#         >>> import ubelt as ub
#         >>> class Baz(ub.NiceRepr):
#         ...    def __len__(self):
#         ...        return 5
#         >>> baz = Baz()
#         >>> assert str(baz) == '<Baz(5)>'
# 
#     Example:
#         >>> import ubelt as ub
#         >>> # If your nice message has a bug, it shouldn't bring down the house
#         >>> class Foo(ub.NiceRepr):
#         ...    def __nice__(self):
#         ...        assert False
#         >>> foo = Foo()
#         >>> import pytest
#         >>> with pytest.warns(RuntimeWarning) as record:
#         >>>     print('foo = {!r}'.format(foo))
#         foo = <...Foo ...>
#     """
# 
#     def __nice__(self):
#         if hasattr(self, '__len__'):
#             # It is a common pattern for objects to use __len__ in __nice__
#             # As a convenience we define a default __nice__ for these objects
#             return str(len(self))
#         else:
#             # In all other cases force the subclass to overload __nice__
#             raise NotImplementedError(
#                 'Define the __nice__ method for {!r}'.format(self.__class__))
# 
#     def __repr__(self):
#         try:
#             nice = self.__nice__()
#             classname = self.__class__.__name__
#             return '<{0}({1}) at {2}>'.format(classname, nice, hex(id(self)))
#         except Exception as ex:
#             warnings.warn(str(ex), category=RuntimeWarning)
#             return object.__repr__(self)
# 
#     def __str__(self):
#         try:
#             classname = self.__class__.__name__
#             nice = self.__nice__()
#             return '<{0}({1})>'.format(classname, nice)
#         except Exception as ex:
#             warnings.warn(str(ex), category=RuntimeWarning)
#             return object.__repr__(self)


# Path: ubelt/util_zip.py
import io
import os
    import re
            import zipfile
            import ubelt as ub
                import tempfile
from os.path import exists, join
from ubelt.util_mixins import NiceRepr

        >>> split_archive('/a/b/foo.zip/baz.pt/bar.zip/bar.zip', '.pt')

    TODO:
        Fix got/want for win32

        (None, None)
        ('/a/b/foo.zip', 'bar.txt')
        ('/a/b/foo.zip/baz/biz.zip', 'bar.py')
        ('archive.zip', None)
        ('/a/b/foo.zip/baz/biz.zip', 'bar.py')
        ('/a/b/foo.zip/baz.pt', 'bar.zip/bar.zip')
    """
    fpath = os.fspath(fpath)
    # fpath = os.fspath(fpath)
    pat = '({}[{}/:])'.format(re.escape(ext), re.escape(os.path.sep))
    # pat = r'(\'' + ext + '[' + re.escape(os.path.sep) + '/:])'
    parts = re.split(pat, fpath, flags=re.IGNORECASE)
    if len(parts) > 2:
        archivepath = ''.join(parts[:-1])[:-1]
        internal = parts[-1]
    elif len(parts) == 1:
        archivepath = parts[0]
        if not archivepath.endswith(ext):
            archivepath = None
        internal = None
    else:  # nocover
        raise AssertionError('impossible state')
    return archivepath, internal



class zopen(NiceRepr):