# Path: groundstation/proto/git_object_pb2.py
# class GitObject(_message.Message):
#   __metaclass__ = _reflection.GeneratedProtocolMessageType
#   DESCRIPTOR = _GITOBJECT
# 
#   # @@protoc_insertion_point(class_scope:GitObject)
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


import groundstation.transfer.request
from groundstation.proto.git_object_pb2 import GitObject
from groundstation import logger


log = logger.getLogger(__name__)

def handle_fetchobject(self):
    log.info("Handling FETCHOBJECT")
    git_obj = self.station[self.payload]
    git_pb = GitObject()

    git_pb.type = git_obj.type
    git_pb.data = git_obj.read_raw()

    response = self._Response(self.id, "TRANSFER", git_pb.SerializeToString())

# Path: groundstation/proto/git_object_pb2.py
# class GitObject(_message.Message):
#   __metaclass__ = _reflection.GeneratedProtocolMessageType
#   DESCRIPTOR = _GITOBJECT
# 
#   # @@protoc_insertion_point(class_scope:GitObject)
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


# Path: groundstation/transfer/request_handlers/fetchobject.py
import groundstation.transfer.request
from groundstation.proto.git_object_pb2 import GitObject
from groundstation import logger



log = logger.getLogger(__name__)

def handle_fetchobject(self):
    log.info("Handling FETCHOBJECT")
    git_obj = self.station[self.payload]
    git_pb = GitObject()

    git_pb.type = git_obj.type
    git_pb.data = git_obj.read_raw()

    response = self._Response(self.id, "TRANSFER", git_pb.SerializeToString())

    self.stream.enqueue(response)