disabled
     �À_’I|¥‰ÓMjqØ‚¦ð¬÷À¿      No input file specified.
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã441_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ ¹    ‹      •“_oÓ0Åß÷).~à­¹mÓ�´9F#©DE×V] Äƒ»‰EGö-Ýøô$M§u¨öä?ŸsmóWÉ<N¿.Æð!½�ÂâÓûé$ÖCüÆˆIšt£ ?@Ï°‚¨¾BÜívÁ.¬Ë1]bA›r„žœÉ(P¤˜¸àíœ¸ ^h©š8*µ˜TJßƒ]Ú-y£ô·Þ¡©²r«4z]Û3SrìøF|eÕC«<x�Jï—«½XÛu‚S?eiò*bdk&¸Ùäà]14™­<®JYýr³f KŠØ·I<ÿÞpHE»[p	…Óëˆ½‹£Ùõ<ºab&7š£<ÍÜvÌTz‚�Ufm´:ßuð�ùu^0é˜DûÌ™šŒ­žPl"GÍlékÙd½lî˜êõ¯jÈìY17Ëñ,M&Ë®$ª•xr÷·;ab!�®ãtFÖ=lw¯«•¯¯‡p0åL^ =8I¾ 	é{:N’~IOfhÞNP0±oŽþaiØ†½þeo8‚Á›«Qpƒ·Ï{ÿÏ»ÂÃ+æ¸ÿ	»?öE1uÆ    6   ˆl–äY>” ”¾R( 	Å ‚vã S�ÿ�þB gäz9DË.;üÿÆƒh¹ÅÄÃ      disabled
  B   	ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þZ(Â³rˆ�†A„% ?ŸÇ„'ÿÆ_ŠI|¥�+Wé3ž¯ÆÅ ?÷     	# Copyright (C) 2007, 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Container format for Bazaar data.

"Containers" and "records" are described in
doc/developers/container-format.txt.
"""

from io import BytesIO
import re

from .. import errors


FORMAT_ONE = b"Bazaar pack format 1 (introduced in 0.18)"


_whitespace_re = re.compile(b'[\t\n\x0b\x0c\r ]')


class ContainerError(errors.BzrError):
    """Base class of container errors."""


class UnknownContainerFormatError(ContainerError):

    _fmt = "Unrecognised container format: %(container_format)r"

    def __init__(self, container_format):
        self.container_format = container_format


class UnexpectedEndOfContainerError(ContainerError):

    _fmt = "Unexpected end of container stream"


class UnknownRecordTypeError(ContainerError):

    _fmt = "Unknown record type: %(record_type)r"

    def __init__(self, record_type):
        self.record_type = record_type


class InvalidRecordError(ContainerError):

    _fmt = "Invalid record: %(reason)s"

    def __init__(self, reason):
        self.reason = reason


class ContainerHasExcessDataError(ContainerError):

    _fmt = "Container has data after end marker: %(excess)r"

    def __init__(self, excess):
        self.excess = excess


class DuplicateRecordNameError(ContainerError):

    _fmt = "Container has multiple records with the same name: %(name)s"

    def __init__(self, name):
        self.name = name.decode("utf-8")


def _check_name(name):
    """Do some basic checking of 'name'.

    At the moment, this just checks that there are no whitespace characters in a
    name.

    :raises InvalidRecordError: if name is not valid.
    :seealso: _check_name_encoding
    """
    if _whitespace_re.search(name) is not None:
        raise InvalidRecordError("{!r} is not a valid name.".format(name))


def _check_name_encoding(name):
    """Check that 'name' is valid UTF-8.

    This is separate from _check_name because UTF-8 decoding is relatively
    expensive, and we usually want to avoid it.

    :raises InvalidRecordError: if name is not valid UTF-8.
    """
    try:
        name.decode('utf-8')
    except UnicodeDecodeError as e:
        raise InvalidRecordError(str(e))


class ContainerSerialiser:
    """A helper class for serialising containers.

    It simply returns bytes from method calls to 'begin', 'end' and
    'bytes_record'.  You may find ContainerWriter to be a more convenient
    interface.
    """

    def begin(self):
        """Return the bytes to begin a container."""
        return FORMAT_ONE + b"\n"

    def end(self):
        """Return the bytes to finish a container."""
        return b"E"
