# Path: binstar_client/utils/notebook/data_uri.py
# def data_uri_from(location):
#     return DataURIConverter(location)()


from os import path
from pprint import pprint
from ..utils.notebook.data_uri import data_uri_from
import json
import re
import sys
import tarfile
import tempfile
                # recipe.index is deprecated and only packages built with older
                # versions of conda-build contain that file.
                recipe = tar.extractfile(info)
                recipe = json.loads(recipe.read().decode())
                about = recipe.pop('about', {})
            elif info.name == 'info/about.json':
                # recipe.json is deprecated and only packages build with older
                # versions of conda-build contain that file.
                about = tar.extractfile(info)
                about = json.loads(about.read().decode())
            elif info.name == 'info/has_prefix':
                has_prefix = True
            if index is not None and about != {}:
                break
        else:
            if index is None:
                raise TypeError("info/index.json required in conda package")

    # Load icon defined in the index.json and file exists inside info folder
    fileobj.seek(0)
    icon_b64 = None
    icon_path = index.get('icon')
    if icon_path:
        tar = tarfile.open(filename, fileobj=fileobj, mode="r|bz2")
        for info in tar:
            if info.name == 'info/{0}'.format(icon_path):
                icon_data = tar.extractfile(info).read()
                f, temp_path = tempfile.mkstemp()
                with open(temp_path, 'wb') as f:
                    f.write(icon_data)

# Path: binstar_client/utils/notebook/data_uri.py
# def data_uri_from(location):
#     return DataURIConverter(location)()


# Path: binstar_client/inspect_package/conda.py
from os import path
from pprint import pprint
from ..utils.notebook.data_uri import data_uri_from
import json
import re
import sys
import tarfile
import tempfile

                # recipe.index is deprecated and only packages built with older
                # versions of conda-build contain that file.
                recipe = tar.extractfile(info)
                recipe = json.loads(recipe.read().decode())
                about = recipe.pop('about', {})
            elif info.name == 'info/about.json':
                # recipe.json is deprecated and only packages build with older
                # versions of conda-build contain that file.
                about = tar.extractfile(info)
                about = json.loads(about.read().decode())
            elif info.name == 'info/has_prefix':
                has_prefix = True
            if index is not None and about != {}:
                break
        else:
            if index is None:
                raise TypeError("info/index.json required in conda package")

    # Load icon defined in the index.json and file exists inside info folder
    fileobj.seek(0)
    icon_b64 = None
    icon_path = index.get('icon')
    if icon_path:
        tar = tarfile.open(filename, fileobj=fileobj, mode="r|bz2")
        for info in tar:
            if info.name == 'info/{0}'.format(icon_path):
                icon_data = tar.extractfile(info).read()
                f, temp_path = tempfile.mkstemp()
                with open(temp_path, 'wb') as f:
                    f.write(icon_data)

                icon_b64 = data_uri_from(temp_path)