# Path: oioswift/common/middleware/versioned_writes.py
# DELETE_MARKER_CONTENT_TYPE = vw.DELETE_MARKER_CONTENT_TYPE
# 
# Path: oioswift/utils.py
# def handle_oio_no_such_container(fnc):
#     """Catch NoSuchContainer errors and return '404 Not Found'"""
#     @wraps(fnc)
#     def _oio_no_such_container_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except NoSuchContainer:
#             return HTTPNotFound(request=req)
#     return _oio_no_such_container_wrapper
# 
# def handle_oio_timeout(fnc):
#     """
#     Catch DeadlineReached and OioTimeout errors
#     and return '503 Service Unavailable'.
#     """
#     @wraps(fnc)
#     def _oio_timeout_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except (DeadlineReached, OioTimeout) as exc:
#             headers = dict()
#             # TODO(FVE): choose the value according to the timeout
#             headers['Retry-After'] = '1'
#             return HTTPServiceUnavailable(request=req, headers=headers,
#                                           body=str(exc))
#     return _oio_timeout_wrapper
# 
# def handle_service_busy(fnc):
#     @wraps(fnc)
#     def _service_busy_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except (ServiceBusy, ServiceUnavailable) as err:
#             headers = dict()
#             headers['Retry-After'] = '1'
#             return HTTPServiceUnavailable(request=req, headers=headers,
#                                           body=err.message)
#     return _service_busy_wrapper
# 
# REQID_HEADER = 'x-oio-req-id'
# 
# BUCKET_NAME_PROP = "sys.m2.bucket.name"
# 
# MULTIUPLOAD_SUFFIX = '+segments'


import json
from xml.etree.cElementTree import Element, SubElement, tostring
from swift.common.utils import public, Timestamp, \
    override_bytes_from_content_type
from swift.common.constraints import check_metadata
from swift.common import constraints
    from swift.common.middleware.listing_formats import \
        get_listing_content_type
    from swift.common.request_helpers import get_listing_content_type
from oioswift.common.middleware.versioned_writes import \
    DELETE_MARKER_CONTENT_TYPE
from swift.common.swob import Response, HTTPBadRequest, HTTPNotFound, \
    HTTPNoContent, HTTPConflict, HTTPPreconditionFailed, HTTPForbidden, \
    HTTPCreated
from swift.common.http import is_success, HTTP_ACCEPTED
from swift.common.request_helpers import is_sys_or_user_meta, get_param
from swift.proxy.controllers.container import ContainerController \
        as SwiftContainerController
from swift.proxy.controllers.base import clear_info_cache, \
    delay_denial, cors_validation, set_info_cache
from oio.common import exceptions
from oioswift.utils import \
    handle_oio_no_such_container, handle_oio_timeout, \
    handle_service_busy, REQID_HEADER, BUCKET_NAME_PROP, MULTIUPLOAD_SUFFIX
                      is_sys_or_user_meta('container', k)):
                headers[k] = v
        return headers

    def get_container_list_resp(self, req):
        path = get_param(req, 'path')
        prefix = get_param(req, 'prefix')
        delimiter = get_param(req, 'delimiter')
        if delimiter and (len(delimiter) > 1 or ord(delimiter) > 254):
            # delimiters can be made more flexible later
            return HTTPPreconditionFailed(body='Bad delimiter')
        marker = get_param(req, 'marker', '')
        end_marker = get_param(req, 'end_marker')
        limit = constraints.CONTAINER_LISTING_LIMIT
        given_limit = get_param(req, 'limit')
        if given_limit and given_limit.isdigit():
            limit = int(given_limit)
            if limit > constraints.CONTAINER_LISTING_LIMIT:
                return HTTPPreconditionFailed(
                    request=req,
                    body='Maximum limit is %d'
                         % constraints.CONTAINER_LISTING_LIMIT)

        out_content_type = get_listing_content_type(req)
        if path is not None:
            prefix = path
            if path:
                prefix = path.rstrip('/') + '/'
            delimiter = '/'
        opts = req.environ.get('oio.query', {})

# Path: oioswift/common/middleware/versioned_writes.py
# DELETE_MARKER_CONTENT_TYPE = vw.DELETE_MARKER_CONTENT_TYPE
# 
# Path: oioswift/utils.py
# def handle_oio_no_such_container(fnc):
#     """Catch NoSuchContainer errors and return '404 Not Found'"""
#     @wraps(fnc)
#     def _oio_no_such_container_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except NoSuchContainer:
#             return HTTPNotFound(request=req)
#     return _oio_no_such_container_wrapper
# 
# def handle_oio_timeout(fnc):
#     """
#     Catch DeadlineReached and OioTimeout errors
#     and return '503 Service Unavailable'.
#     """
#     @wraps(fnc)
#     def _oio_timeout_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except (DeadlineReached, OioTimeout) as exc:
#             headers = dict()
#             # TODO(FVE): choose the value according to the timeout
#             headers['Retry-After'] = '1'
#             return HTTPServiceUnavailable(request=req, headers=headers,
#                                           body=str(exc))
#     return _oio_timeout_wrapper
# 
# def handle_service_busy(fnc):
#     @wraps(fnc)
#     def _service_busy_wrapper(self, req, *args, **kwargs):
#         try:
#             return fnc(self, req, *args, **kwargs)
#         except (ServiceBusy, ServiceUnavailable) as err:
#             headers = dict()
#             headers['Retry-After'] = '1'
#             return HTTPServiceUnavailable(request=req, headers=headers,
#                                           body=err.message)
#     return _service_busy_wrapper
# 
# REQID_HEADER = 'x-oio-req-id'
# 
# BUCKET_NAME_PROP = "sys.m2.bucket.name"
# 
# MULTIUPLOAD_SUFFIX = '+segments'


# Path: oioswift/proxy/controllers/container.py
import json
from xml.etree.cElementTree import Element, SubElement, tostring
from swift.common.utils import public, Timestamp, \
    override_bytes_from_content_type
from swift.common.constraints import check_metadata
from swift.common import constraints
    from swift.common.middleware.listing_formats import \
        get_listing_content_type
    from swift.common.request_helpers import get_listing_content_type
from oioswift.common.middleware.versioned_writes import \
    DELETE_MARKER_CONTENT_TYPE
from swift.common.swob import Response, HTTPBadRequest, HTTPNotFound, \
    HTTPNoContent, HTTPConflict, HTTPPreconditionFailed, HTTPForbidden, \
    HTTPCreated
from swift.common.http import is_success, HTTP_ACCEPTED
from swift.common.request_helpers import is_sys_or_user_meta, get_param
from swift.proxy.controllers.container import ContainerController \
        as SwiftContainerController
from swift.proxy.controllers.base import clear_info_cache, \
    delay_denial, cors_validation, set_info_cache
from oio.common import exceptions
from oioswift.utils import \
    handle_oio_no_such_container, handle_oio_timeout, \
    handle_service_busy, REQID_HEADER, BUCKET_NAME_PROP, MULTIUPLOAD_SUFFIX

                      is_sys_or_user_meta('container', k)):
                headers[k] = v
        return headers

    def get_container_list_resp(self, req):
        path = get_param(req, 'path')
        prefix = get_param(req, 'prefix')
        delimiter = get_param(req, 'delimiter')
        if delimiter and (len(delimiter) > 1 or ord(delimiter) > 254):
            # delimiters can be made more flexible later
            return HTTPPreconditionFailed(body='Bad delimiter')
        marker = get_param(req, 'marker', '')
        end_marker = get_param(req, 'end_marker')
        limit = constraints.CONTAINER_LISTING_LIMIT
        given_limit = get_param(req, 'limit')
        if given_limit and given_limit.isdigit():
            limit = int(given_limit)
            if limit > constraints.CONTAINER_LISTING_LIMIT:
                return HTTPPreconditionFailed(
                    request=req,
                    body='Maximum limit is %d'
                         % constraints.CONTAINER_LISTING_LIMIT)

        out_content_type = get_listing_content_type(req)
        if path is not None:
            prefix = path
            if path:
                prefix = path.rstrip('/') + '/'
            delimiter = '/'
        opts = req.environ.get('oio.query', {})

        oio_headers = {REQID_HEADER: self.trans_id}