# Path: microcosm_pubsub/constants.py
# DEFAULT_RESOURCE_CACHE_TTL = 60
# 
# Path: microcosm_pubsub/conventions/lifecycle.py
# class LifecycleChange(set):
#     """
#     A collection of CRUD lifecycle transitions that may be announced via pubsub.
# 
#     Note that `Changed` is strongly discouraged; use immutable resources instead.
# 
#     """
#     Changed = "changed"
#     Created = "created"
#     Deleted = "deleted"
# 
#     def __init__(self, graph):
#         super().__init__([
#             LifecycleChange.Changed,
#             LifecycleChange.Created,
#             LifecycleChange.Deleted,
#         ])
# 
#     def matches(self, media_type):
#         parts = media_type.split(".")
#         return any(
#             item in parts
#             for item in self
#         )
# 
# Path: microcosm_pubsub/errors.py
# class Nack(Exception):
#     """
#     Retry the message after a configured number of seconds.
# 
#     Note that retry behavior is contingent on both the backoff policy
#     and the SQS dead letter queue (DLQ) configuration, if any.
# 
#     """
#     def __init__(self, visibility_timeout_seconds):
#         self.visibility_timeout_seconds = visibility_timeout_seconds
# 
#     def __repr__(self):
#         return "Nack({})".format(self.visibility_timeout_seconds)


from abc import ABCMeta
from re import search
from inflection import titleize
from microcosm.errors import LockedGraphError, NotBoundError
from microcosm_logging.decorators import logger
from requests import codes, get
from requests.exceptions import InvalidSchema
from microcosm_pubsub.constants import DEFAULT_RESOURCE_CACHE_TTL
from microcosm_pubsub.conventions.lifecycle import LifecycleChange
from microcosm_pubsub.errors import Nack
                raise Nack(self.resource_nack_timeout)

    def get_resource(self, message, uri):
        """
        Mock-friendly URI getter.

        Passes message context.

        """
        if self.resource_cache and self.resource_cache_whitelist_callable(
            media_type=message.get("mediaType"),
            uri=uri
        ):
            response = self.resource_cache.get(uri)
            if response:
                return response

        headers = self.get_headers(message)
        try:
            response = get(uri, headers=headers)
        except InvalidSchema:
            self.logger.error(
                "Error was found when trying to process uri. Check schema",
                extra=dict(
                    handler=self.name,
                    uri=uri,
                ),
            )
            raise
        if response.status_code == codes.not_found and self.nack_if_not_found:

# Path: microcosm_pubsub/constants.py
# DEFAULT_RESOURCE_CACHE_TTL = 60
# 
# Path: microcosm_pubsub/conventions/lifecycle.py
# class LifecycleChange(set):
#     """
#     A collection of CRUD lifecycle transitions that may be announced via pubsub.
# 
#     Note that `Changed` is strongly discouraged; use immutable resources instead.
# 
#     """
#     Changed = "changed"
#     Created = "created"
#     Deleted = "deleted"
# 
#     def __init__(self, graph):
#         super().__init__([
#             LifecycleChange.Changed,
#             LifecycleChange.Created,
#             LifecycleChange.Deleted,
#         ])
# 
#     def matches(self, media_type):
#         parts = media_type.split(".")
#         return any(
#             item in parts
#             for item in self
#         )
# 
# Path: microcosm_pubsub/errors.py
# class Nack(Exception):
#     """
#     Retry the message after a configured number of seconds.
# 
#     Note that retry behavior is contingent on both the backoff policy
#     and the SQS dead letter queue (DLQ) configuration, if any.
# 
#     """
#     def __init__(self, visibility_timeout_seconds):
#         self.visibility_timeout_seconds = visibility_timeout_seconds
# 
#     def __repr__(self):
#         return "Nack({})".format(self.visibility_timeout_seconds)


# Path: microcosm_pubsub/handlers/uri_handler.py
from abc import ABCMeta
from re import search
from inflection import titleize
from microcosm.errors import LockedGraphError, NotBoundError
from microcosm_logging.decorators import logger
from requests import codes, get
from requests.exceptions import InvalidSchema
from microcosm_pubsub.constants import DEFAULT_RESOURCE_CACHE_TTL
from microcosm_pubsub.conventions.lifecycle import LifecycleChange
from microcosm_pubsub.errors import Nack

                raise Nack(self.resource_nack_timeout)

    def get_resource(self, message, uri):
        """
        Mock-friendly URI getter.

        Passes message context.

        """
        if self.resource_cache and self.resource_cache_whitelist_callable(
            media_type=message.get("mediaType"),
            uri=uri
        ):
            response = self.resource_cache.get(uri)
            if response:
                return response

        headers = self.get_headers(message)
        try:
            response = get(uri, headers=headers)
        except InvalidSchema:
            self.logger.error(
                "Error was found when trying to process uri. Check schema",
                extra=dict(
                    handler=self.name,
                    uri=uri,
                ),
            )
            raise
        if response.status_code == codes.not_found and self.nack_if_not_found:

            raise Nack(self.resource_nack_timeout)