# Path: apitools/base/py/encoding.py
# _UNRECOGNIZED_FIELD_MAPPINGS = {}
# _CUSTOM_MESSAGE_CODECS = {}
# _CUSTOM_FIELD_CODECS = {}
# _FIELD_TYPE_CODECS = {}
#   _INSTANCE = None
# _JSON_ENUM_MAPPINGS = {}
# _JSON_FIELD_MAPPINGS = {}
# def MapUnrecognizedFields(field_name):
#   def Register(cls):
# def RegisterCustomMessageCodec(encoder, decoder):
#   def Register(cls):
# def RegisterCustomFieldCodec(encoder, decoder):
#   def Register(field):
# def RegisterFieldTypeCodec(encoder, decoder):
#   def Register(field_type):
# def CopyProtoMessage(message):
# def MessageToJson(message, include_fields=None):
# def JsonToMessage(message_type, message):
# def DictToMessage(d, message_type):
# def MessageToDict(message):
# def PyValueToMessage(message_type, value):
# def MessageToPyValue(message):
# def MessageToRepr(msg, multiline=False, **kwargs):
#   def IndentKwargs(kwargs):
#       def __init__(self, offset):
#       def __repr__(self):
# def _GetField(message, field_path):
# def _SetField(dictblob, field_path, value):
# def _IncludeFields(encoded_message, message, include_fields):
# def _GetFieldCodecs(field, attr):
#   def Get(cls):
#   def decode_message(self, message_type, encoded_message):
#   def decode_field(self, field, value):
#   def encode_message(self, message):
#   def encode_field(self, field, value):
# def _DecodeUnknownFields(message, encoded_message):
# def _DecodeUnknownMessages(message, encoded_message, pair_type):
# def _DecodeUnrecognizedFields(message, pair_type):
# def _EncodeUnknownFields(message):
# def _SafeEncodeBytes(field, value):
# def _SafeDecodeBytes(unused_field, value):
# def _ProcessUnknownEnums(message, encoded_message):
# def _ProcessUnknownMessages(message, encoded_message):
# def AddCustomJsonEnumMapping(enum_type, python_name, json_name):
# def AddCustomJsonFieldMapping(message_type, python_name, json_name):
# def GetCustomJsonEnumMapping(enum_type, python_name=None, json_name=None):
# def GetCustomJsonFieldMapping(message_type, python_name=None, json_name=None):
# def _FetchRemapping(type_name, mapping_type, python_name=None, json_name=None,
#                     mappings=None):
# def _CheckForExistingMappings(mapping_type, message_type,
#                               python_name, json_name):
# def _EncodeCustomFieldNames(message, encoded_value):
# def _DecodeCustomFieldNames(message_type, encoded_message):
#     class SpecialTZInfo(datetime.tzinfo):
# class _ProtoJsonApiTools(protojson.ProtoJson):
# 
# Path: apitools/base/py/exceptions.py
# class Error(Exception):
# class TypecheckError(Error, TypeError):
# class NotFoundError(Error):
# class UserError(Error):
# class InvalidDataError(Error):
# class CommunicationError(Error):
# class HttpError(CommunicationError):
# class InvalidUserInputError(InvalidDataError):
# class InvalidDataFromServerError(InvalidDataError, CommunicationError):
# class BatchError(Error):
# class ConfigurationError(Error):
# class GeneratedClientError(Error):
# class ConfigurationValueError(UserError):
# class ResourceUnavailableError(Error):
# class CredentialsError(Error):
# class TransferError(CommunicationError):
# class TransferRetryError(TransferError):
# class TransferInvalidError(TransferError):
# class RequestError(CommunicationError):
# class RetryAfterError(HttpError):
# class BadStatusCodeError(HttpError):
# class NotYetImplementedError(GeneratedClientError):
# class StreamExhausted(Error):
#   def __init__(self, response, content, url):
#   def __str__(self):
#   def status_code(self):
#   def FromResponse(cls, http_response):
#   def __init__(self, response, content, url, retry_after):
#   def FromResponse(cls, http_response):


import collections
import os
import random
import six
import six.moves.urllib.error as urllib_error
import six.moves.urllib.parse as urllib_parse
import six.moves.urllib.request as urllib_request
from protorpc import messages
from six.moves import http_client
from apitools.base.py import encoding
from apitools.base.py import exceptions
  Note that this function assumes that all patterns in accept_patterns
  will be simple types of the form "type/subtype", where one or both
  of these can be "*". We do not support parameters (i.e. "; q=") in
  patterns.

  Args:
    accept_patterns: list of acceptable MIME types.
    mime_type: the mime type we would like to match.

  Returns:
    Whether or not mime_type matches (at least) one of these patterns.
  """
  unsupported_patterns = [p for p in accept_patterns if ';' in p]
  if unsupported_patterns:
    raise exceptions.GeneratedClientError(
        'MIME patterns with parameter unsupported: "%s"' % ', '.join(
            unsupported_patterns))
  def MimeTypeMatches(pattern, mime_type):
    """Return True iff mime_type is acceptable for pattern."""
    # Some systems use a single '*' instead of '*/*'.
    if pattern == '*':
      pattern = '*/*'
    return all(accept in ('*', provided) for accept, provided
               in zip(pattern.split('/'), mime_type.split('/')))

  return any(MimeTypeMatches(pattern, mime_type) for pattern in accept_patterns)


def MapParamNames(params, request_type):
  """Reverse parameter remappings for URL construction."""

# Path: apitools/base/py/encoding.py
# _UNRECOGNIZED_FIELD_MAPPINGS = {}
# _CUSTOM_MESSAGE_CODECS = {}
# _CUSTOM_FIELD_CODECS = {}
# _FIELD_TYPE_CODECS = {}
#   _INSTANCE = None
# _JSON_ENUM_MAPPINGS = {}
# _JSON_FIELD_MAPPINGS = {}
# def MapUnrecognizedFields(field_name):
#   def Register(cls):
# def RegisterCustomMessageCodec(encoder, decoder):
#   def Register(cls):
# def RegisterCustomFieldCodec(encoder, decoder):
#   def Register(field):
# def RegisterFieldTypeCodec(encoder, decoder):
#   def Register(field_type):
# def CopyProtoMessage(message):
# def MessageToJson(message, include_fields=None):
# def JsonToMessage(message_type, message):
# def DictToMessage(d, message_type):
# def MessageToDict(message):
# def PyValueToMessage(message_type, value):
# def MessageToPyValue(message):
# def MessageToRepr(msg, multiline=False, **kwargs):
#   def IndentKwargs(kwargs):
#       def __init__(self, offset):
#       def __repr__(self):
# def _GetField(message, field_path):
# def _SetField(dictblob, field_path, value):
# def _IncludeFields(encoded_message, message, include_fields):
# def _GetFieldCodecs(field, attr):
#   def Get(cls):
#   def decode_message(self, message_type, encoded_message):
#   def decode_field(self, field, value):
#   def encode_message(self, message):
#   def encode_field(self, field, value):
# def _DecodeUnknownFields(message, encoded_message):
# def _DecodeUnknownMessages(message, encoded_message, pair_type):
# def _DecodeUnrecognizedFields(message, pair_type):
# def _EncodeUnknownFields(message):
# def _SafeEncodeBytes(field, value):
# def _SafeDecodeBytes(unused_field, value):
# def _ProcessUnknownEnums(message, encoded_message):
# def _ProcessUnknownMessages(message, encoded_message):
# def AddCustomJsonEnumMapping(enum_type, python_name, json_name):
# def AddCustomJsonFieldMapping(message_type, python_name, json_name):
# def GetCustomJsonEnumMapping(enum_type, python_name=None, json_name=None):
# def GetCustomJsonFieldMapping(message_type, python_name=None, json_name=None):
# def _FetchRemapping(type_name, mapping_type, python_name=None, json_name=None,
#                     mappings=None):
# def _CheckForExistingMappings(mapping_type, message_type,
#                               python_name, json_name):
# def _EncodeCustomFieldNames(message, encoded_value):
# def _DecodeCustomFieldNames(message_type, encoded_message):
#     class SpecialTZInfo(datetime.tzinfo):
# class _ProtoJsonApiTools(protojson.ProtoJson):
# 
# Path: apitools/base/py/exceptions.py
# class Error(Exception):
# class TypecheckError(Error, TypeError):
# class NotFoundError(Error):
# class UserError(Error):
# class InvalidDataError(Error):
# class CommunicationError(Error):
# class HttpError(CommunicationError):
# class InvalidUserInputError(InvalidDataError):
# class InvalidDataFromServerError(InvalidDataError, CommunicationError):
# class BatchError(Error):
# class ConfigurationError(Error):
# class GeneratedClientError(Error):
# class ConfigurationValueError(UserError):
# class ResourceUnavailableError(Error):
# class CredentialsError(Error):
# class TransferError(CommunicationError):
# class TransferRetryError(TransferError):
# class TransferInvalidError(TransferError):
# class RequestError(CommunicationError):
# class RetryAfterError(HttpError):
# class BadStatusCodeError(HttpError):
# class NotYetImplementedError(GeneratedClientError):
# class StreamExhausted(Error):
#   def __init__(self, response, content, url):
#   def __str__(self):
#   def status_code(self):
#   def FromResponse(cls, http_response):
#   def __init__(self, response, content, url, retry_after):
#   def FromResponse(cls, http_response):


# Path: apitools/base/py/util.py
import collections
import os
import random
import six
import six.moves.urllib.error as urllib_error
import six.moves.urllib.parse as urllib_parse
import six.moves.urllib.request as urllib_request
from protorpc import messages
from six.moves import http_client
from apitools.base.py import encoding
from apitools.base.py import exceptions

  Note that this function assumes that all patterns in accept_patterns
  will be simple types of the form "type/subtype", where one or both
  of these can be "*". We do not support parameters (i.e. "; q=") in
  patterns.

  Args:
    accept_patterns: list of acceptable MIME types.
    mime_type: the mime type we would like to match.

  Returns:
    Whether or not mime_type matches (at least) one of these patterns.
  """
  unsupported_patterns = [p for p in accept_patterns if ';' in p]
  if unsupported_patterns:
    raise exceptions.GeneratedClientError(
        'MIME patterns with parameter unsupported: "%s"' % ', '.join(
            unsupported_patterns))
  def MimeTypeMatches(pattern, mime_type):
    """Return True iff mime_type is acceptable for pattern."""
    # Some systems use a single '*' instead of '*/*'.
    if pattern == '*':
      pattern = '*/*'
    return all(accept in ('*', provided) for accept, provided
               in zip(pattern.split('/'), mime_type.split('/')))

  return any(MimeTypeMatches(pattern, mime_type) for pattern in accept_patterns)


def MapParamNames(params, request_type):
  """Reverse parameter remappings for URL construction."""

  return [encoding.GetCustomJsonFieldMapping(request_type, json_name=p) or p