# Path: bdec/constraints.py
# class Equals(Constraint):
#     type = '!='
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(expected, int):
#             if int(value) !=  expected:
#                 raise ConstraintError(entry, int(value), '==', expected)
#         elif isinstance(expected, Data):
#             # We aren't checking the length here, only the value (for example,
#             # the expected value for a variable length binary field will have
#             # a different length than the actual). Only compare the bits that
#             # are valid.
#             length_diff = len(value) - len(expected)
#             if length_diff > 0:
#                 # The expected value is shorter than the actual, so grow it.
#                 expected = Data('\x00' * (length_diff / 8 + 1), 0, length_diff) + expected
#             elif length_diff < 0:
#                 # The expected value is longer than the actual, so shrink it.
#                 shorter = expected.copy()
#                 leading = shorter.pop(-length_diff)
#                 if not int(leading):
#                     # We can safely pop the leading bits.
#                     expected = shorter
#             if value !=  expected:
#                 raise ConstraintError(entry, value, '==', expected)
#         else:
#             if value !=  expected:
#                 raise ConstraintError(entry, value, '==', expected)
# 
#     def range(self):
#         limit = _limit(self.limit)
#         return Range(limit, limit)
# 
# class Maximum(Constraint):
#     type = '>'
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(value, basestring):
#             # It is useful to check the bounds of a text character...
#             value = ord(value)
#         if int(value) > expected:
#             raise ConstraintError(entry, int(value), '<=', expected)
# 
#     def range(self):
#         return Range(None, _limit(self.limit))
# 
# class Minimum(Constraint):
#     type = '<'
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(value, basestring):
#             # It is useful to check the bounds of a text character...
#             value = ord(value)
#         if int(value) < expected:
#             raise ConstraintError(entry, int(value), '>=', expected)
# 
#     def range(self):
#         return Range(_limit(self.limit), None)
# 
# Path: bdec/inspect/param.py
# class UnknownReferenceError(BadReferenceError):
#     def __init__(self, entry, name, entries=[]):
#         BadReferenceError.__init__(self, entry, entries)
#         self.name = name
# 
#     def __str__(self):
#         return "%s references unknown entry '%s'!" % (self.entry, self.name)


import operator
import bdec.choice as chc
import bdec.data as dt
import bdec.entry as ent
import bdec.expression as expr
import bdec.field as fld
import bdec.sequence as seq
import bdec.sequenceof as sof
from bdec.constraints import Equals, Maximum, Minimum
from bdec.inspect.param import UnknownReferenceError
from collections import defaultdict
                # next child.
                return [_ProtocolStream(self.entry.children[offset].entry, self, offset)]
            assert offset == len(self.entry.children)
        elif isinstance(self.entry, chc.Choice):
            # The next entry of the choice is all of its children. After that
            # we must go back up to the parent.
            if offset == 0:
                return [_ProtocolStream(child.entry, self, 0) for child in self.entry.children]

        # We don't have any more embedded items; go back up to the parent.
        if self._parent is None:
            return []
        return self._parent._next(self._parent_offset+1)

    def __eq__(self, other):
        if self.entry is not other.entry:
            return False
        if self._parent is not other._parent:
            return False
        if self._parent_offset != other._parent_offset:
            return False
        return self.data == other.data

    def next(self):
        """Return an iterator to _ProtocolStream items"""
        return self._next(0)

    def _create_data(self):
        """Return a data instance, or None if one doesn't exist for this entry."""
        if isinstance(self.entry, fld.Field):

# Path: bdec/constraints.py
# class Equals(Constraint):
#     type = '!='
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(expected, int):
#             if int(value) !=  expected:
#                 raise ConstraintError(entry, int(value), '==', expected)
#         elif isinstance(expected, Data):
#             # We aren't checking the length here, only the value (for example,
#             # the expected value for a variable length binary field will have
#             # a different length than the actual). Only compare the bits that
#             # are valid.
#             length_diff = len(value) - len(expected)
#             if length_diff > 0:
#                 # The expected value is shorter than the actual, so grow it.
#                 expected = Data('\x00' * (length_diff / 8 + 1), 0, length_diff) + expected
#             elif length_diff < 0:
#                 # The expected value is longer than the actual, so shrink it.
#                 shorter = expected.copy()
#                 leading = shorter.pop(-length_diff)
#                 if not int(leading):
#                     # We can safely pop the leading bits.
#                     expected = shorter
#             if value !=  expected:
#                 raise ConstraintError(entry, value, '==', expected)
#         else:
#             if value !=  expected:
#                 raise ConstraintError(entry, value, '==', expected)
# 
#     def range(self):
#         limit = _limit(self.limit)
#         return Range(limit, limit)
# 
# class Maximum(Constraint):
#     type = '>'
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(value, basestring):
#             # It is useful to check the bounds of a text character...
#             value = ord(value)
#         if int(value) > expected:
#             raise ConstraintError(entry, int(value), '<=', expected)
# 
#     def range(self):
#         return Range(None, _limit(self.limit))
# 
# class Minimum(Constraint):
#     type = '<'
# 
#     def check(self, entry, value, context):
#         expected = self.limit.evaluate(context)
#         if isinstance(value, basestring):
#             # It is useful to check the bounds of a text character...
#             value = ord(value)
#         if int(value) < expected:
#             raise ConstraintError(entry, int(value), '>=', expected)
# 
#     def range(self):
#         return Range(_limit(self.limit), None)
# 
# Path: bdec/inspect/param.py
# class UnknownReferenceError(BadReferenceError):
#     def __init__(self, entry, name, entries=[]):
#         BadReferenceError.__init__(self, entry, entries)
#         self.name = name
# 
#     def __str__(self):
#         return "%s references unknown entry '%s'!" % (self.entry, self.name)


# Path: bdec/inspect/chooser.py
import operator
import bdec.choice as chc
import bdec.data as dt
import bdec.entry as ent
import bdec.expression as expr
import bdec.field as fld
import bdec.sequence as seq
import bdec.sequenceof as sof
from bdec.constraints import Equals, Maximum, Minimum
from bdec.inspect.param import UnknownReferenceError
from collections import defaultdict

                # next child.
                return [_ProtocolStream(self.entry.children[offset].entry, self, offset)]
            assert offset == len(self.entry.children)
        elif isinstance(self.entry, chc.Choice):
            # The next entry of the choice is all of its children. After that
            # we must go back up to the parent.
            if offset == 0:
                return [_ProtocolStream(child.entry, self, 0) for child in self.entry.children]

        # We don't have any more embedded items; go back up to the parent.
        if self._parent is None:
            return []
        return self._parent._next(self._parent_offset+1)

    def __eq__(self, other):
        if self.entry is not other.entry:
            return False
        if self._parent is not other._parent:
            return False
        if self._parent_offset != other._parent_offset:
            return False
        return self.data == other.data

    def next(self):
        """Return an iterator to _ProtocolStream items"""
        return self._next(0)

    def _create_data(self):
        """Return a data instance, or None if one doesn't exist for this entry."""
        if isinstance(self.entry, fld.Field):

            value = _get_constraint(self.entry, Equals)