# Path: rest_framework_tus/signals.py

# 
# Path: rest_framework_tus/states.py
# INITIAL = 'initial'
# RECEIVING = 'receiving'
# SAVING = 'saving'
# DONE = 'done'
# 
# Path: rest_framework_tus/utils.py
# def write_bytes_to_file(file_path, offset, bytes, makedirs=False):
#     """
#     Util to write bytes to a local file at a specific offset
# 
#     :param str file_path:
#     :param int offset:
#     :param six.binary_type bytes:
#     :param bool makedirs: Whether or not to create the file_path's directories if they don't exist
#     :return int: The amount of bytes written
#     """
#     if makedirs:
#         if not os.path.isdir(os.path.dirname(file_path)):
#             os.makedirs(os.path.dirname(file_path))
# 
#     num_bytes_written = -1
# 
#     fh = None
#     try:
#         try:
#             fh = open(file_path, 'r+b')
#         except IOError:
#             fh = open(file_path, 'wb')
#         fh.seek(offset, os.SEEK_SET)
#         num_bytes_written = fh.write(bytes)
#     finally:
#         if fh is not None:
#             fh.close()
# 
#     # For python version < 3, "fh.write" will return None...
#     if sys.version_info[0] < 3:
#         num_bytes_written = len(bytes)
# 
#     return num_bytes_written


import collections
import os
import tempfile
import uuid
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_fsm import FSMField, transition
from jsonfield import JSONField
from rest_framework_tus import signals
from rest_framework_tus import states
from rest_framework_tus.utils import write_bytes_to_file
    from django.apps import apps as django_apps
    from .settings import TUS_UPLOAD_MODEL
# -*- coding: utf-8 -*-
from __future__ import unicode_literals





class AbstractUpload(models.Model):
    """
    Abstract model for managing TUS uploads
    """
    guid = models.UUIDField(_('GUID'), default=uuid.uuid4, unique=True)


# Path: rest_framework_tus/signals.py

# 
# Path: rest_framework_tus/states.py
# INITIAL = 'initial'
# RECEIVING = 'receiving'
# SAVING = 'saving'
# DONE = 'done'
# 
# Path: rest_framework_tus/utils.py
# def write_bytes_to_file(file_path, offset, bytes, makedirs=False):
#     """
#     Util to write bytes to a local file at a specific offset
# 
#     :param str file_path:
#     :param int offset:
#     :param six.binary_type bytes:
#     :param bool makedirs: Whether or not to create the file_path's directories if they don't exist
#     :return int: The amount of bytes written
#     """
#     if makedirs:
#         if not os.path.isdir(os.path.dirname(file_path)):
#             os.makedirs(os.path.dirname(file_path))
# 
#     num_bytes_written = -1
# 
#     fh = None
#     try:
#         try:
#             fh = open(file_path, 'r+b')
#         except IOError:
#             fh = open(file_path, 'wb')
#         fh.seek(offset, os.SEEK_SET)
#         num_bytes_written = fh.write(bytes)
#     finally:
#         if fh is not None:
#             fh.close()
# 
#     # For python version < 3, "fh.write" will return None...
#     if sys.version_info[0] < 3:
#         num_bytes_written = len(bytes)
# 
#     return num_bytes_written


# Path: rest_framework_tus/models.py
import collections
import os
import tempfile
import uuid
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_fsm import FSMField, transition
from jsonfield import JSONField
from rest_framework_tus import signals
from rest_framework_tus import states
from rest_framework_tus.utils import write_bytes_to_file
    from django.apps import apps as django_apps
    from .settings import TUS_UPLOAD_MODEL

# -*- coding: utf-8 -*-
from __future__ import unicode_literals





class AbstractUpload(models.Model):
    """
    Abstract model for managing TUS uploads
    """
    guid = models.UUIDField(_('GUID'), default=uuid.uuid4, unique=True)


    state = FSMField(default=states.INITIAL)