# Path: g_sorcery/compatibility.py
# class TemporaryDirectory(object):
#     def __init__(self):
#         self.name = mkdtemp()
# 
#     def __del__(self):
#         shutil.rmtree(self.name)
# 
# Path: g_sorcery/exceptions.py
# class FileJSONError(GSorceryError):
#     pass
# 
# class DownloadingError(GSorceryError):
#     pass
# 
# Path: g_sorcery/serialization.py
# class JSONSerializer(json.JSONEncoder):
#     """
#     Custom JSON encoder.
# 
#     Each serializable class should have a method serialize
#     that returns JSON serializable value. If class additionally
#     has a classmethod deserialize that it can be deserialized
#     and additional metainformation is added to the resulting JSON.
#     """
#     def default(self, obj):
#         res = step_to_raw_serializable(obj)
#         if res:
#             return res
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# def deserializeHook(json_object):
#     """
#     Custom JSON decoder.
# 
#     Each class that can be deserialized should have classmethod deserialize
#     that takes value (previously returned by serialize method) and transforms
#     it into class instance.
#     """
#     return step_from_raw_serializable(json_object)


import glob
import json
import hashlib
import os
import tarfile
from .compatibility import TemporaryDirectory
from .exceptions import FileJSONError, DownloadingError
from .serialization import JSONSerializer, deserializeHook
            os.makedirs(self.directory)
        self.write_content(content)

    def write_content(self, content):
        """
        Real write operation with serialization. Should be overridden.
        """
        pass


class FileJSON(FileJSONData):
    """
    Class for JSON files. Supports custom JSON serialization
    provided by g_sorcery.serialization.
    """

    def read_content(self):
        """
        Read JSON file.
        """
        content = {}
        with open(self.path, 'r') as f:
            content = json.load(f, object_hook=deserializeHook)
        return content

    def write_content(self, content):
        """
        Write JSON file.
        """
        with open(self.path, 'w') as f:

# Path: g_sorcery/compatibility.py
# class TemporaryDirectory(object):
#     def __init__(self):
#         self.name = mkdtemp()
# 
#     def __del__(self):
#         shutil.rmtree(self.name)
# 
# Path: g_sorcery/exceptions.py
# class FileJSONError(GSorceryError):
#     pass
# 
# class DownloadingError(GSorceryError):
#     pass
# 
# Path: g_sorcery/serialization.py
# class JSONSerializer(json.JSONEncoder):
#     """
#     Custom JSON encoder.
# 
#     Each serializable class should have a method serialize
#     that returns JSON serializable value. If class additionally
#     has a classmethod deserialize that it can be deserialized
#     and additional metainformation is added to the resulting JSON.
#     """
#     def default(self, obj):
#         res = step_to_raw_serializable(obj)
#         if res:
#             return res
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# def deserializeHook(json_object):
#     """
#     Custom JSON decoder.
# 
#     Each class that can be deserialized should have classmethod deserialize
#     that takes value (previously returned by serialize method) and transforms
#     it into class instance.
#     """
#     return step_from_raw_serializable(json_object)


# Path: g_sorcery/fileutils.py
import glob
import json
import hashlib
import os
import tarfile
from .compatibility import TemporaryDirectory
from .exceptions import FileJSONError, DownloadingError
from .serialization import JSONSerializer, deserializeHook

            os.makedirs(self.directory)
        self.write_content(content)

    def write_content(self, content):
        """
        Real write operation with serialization. Should be overridden.
        """
        pass


class FileJSON(FileJSONData):
    """
    Class for JSON files. Supports custom JSON serialization
    provided by g_sorcery.serialization.
    """

    def read_content(self):
        """
        Read JSON file.
        """
        content = {}
        with open(self.path, 'r') as f:
            content = json.load(f, object_hook=deserializeHook)
        return content

    def write_content(self, content):
        """
        Write JSON file.
        """
        with open(self.path, 'w') as f:

            json.dump(content, f, indent=2, sort_keys=True, cls=JSONSerializer)