# Path: bdec/expression.py
# class Expression(object):
#     """
#     An object that returns a value given the current decode context.
#     """
#     def evaluate(self, context):
#         raise NotImplementedError
# 
#     def __mul__(self, other):
#         return ArithmeticExpression(operator.mul, self, other)
# 
#     def __div__(self, other):
#         return ArithmeticExpression(operator.div, self, other)
# 
#     def __mod__(self, other):
#         return ArithmeticExpression(operator.mod, self, other)
# 
#     def __add__(self, other):
#         return ArithmeticExpression(operator.add, self, other)
# 
#     def __sub__(self, other):
#         return ArithmeticExpression(operator.sub, self, other)
# 
#     def __lshift__(self, other):
#         return ArithmeticExpression(operator.lshift, self, other)
# 
#     def __rshift__(self, other):
#         return ArithmeticExpression(operator.rshift, self, other)
# 
# class Constant(Expression):
#     def __init__(self, value):
#         self.value = value
#         
#     def evaluate(self, context):
#         return self.value
# 
#     def __repr__(self):
#         if isinstance(self.value, dt.Data):
#             value = self.value
#             if len(value) % 8:
#                 # We can only convert bytes to hex, so added a '0' data
#                 # object in front.
#                 leading_bits = 8 - len(value) % 8
#                 value = dt.Data('\x00', start=0, end=leading_bits) + value
#             return '0x%s' % value.get_hex()
#         return str(self.value)
# 
# class UndecodedReferenceError(Exception):
#     """
#     Raised when a decoded entry is referenced (but unused).
# 
#     We don't derive this from DecodeError, as it is an internal program error.
#     """
#     def __init__(self, name, context):
#         self.name = name
#         self.context = context
# 
#     def __str__(self):
#         return "Missing context '%s' (have %s)" % (self.name,
#                 ', '.join("'%s'" % k for k in self.context.keys()))


import operator
import bdec
import bdec.data as dt
from bdec.expression import Expression, Constant, UndecodedReferenceError
        from bdec.spec.references import ReferencedEntry
            from bdec.decode import Decoder
            from bdec.encode import create_encoder
#       * Redistributions in binary form must reproduce the above copyright
#         notice, this list of conditions and the following disclaimer in the
#         documentation and/or other materials provided with the distribution.
#       * Neither the name of the PRESENSE Technologies GmbH nor the
#         names of its contributors may be used to endorse or promote products
#         derived from this software without specific prior written permission.
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#   DISCLAIMED. IN NO EVENT SHALL PRESENSE Technologies GmbH BE LIABLE FOR ANY
#   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
The bdec.entry module defines the core entry class (bdec.entry.Entry) and 
errors (derived from bdec.DecodeError) common to all entry types.
"""



class EntryDataError(bdec.DecodeError):
    """Error raised when an error was found with the entries data.
    
    For example, not enough data was available to decode this entry."""
    def __init__(self, entry, ex):
        bdec.DecodeError.__init__(self, entry)

# Path: bdec/expression.py
# class Expression(object):
#     """
#     An object that returns a value given the current decode context.
#     """
#     def evaluate(self, context):
#         raise NotImplementedError
# 
#     def __mul__(self, other):
#         return ArithmeticExpression(operator.mul, self, other)
# 
#     def __div__(self, other):
#         return ArithmeticExpression(operator.div, self, other)
# 
#     def __mod__(self, other):
#         return ArithmeticExpression(operator.mod, self, other)
# 
#     def __add__(self, other):
#         return ArithmeticExpression(operator.add, self, other)
# 
#     def __sub__(self, other):
#         return ArithmeticExpression(operator.sub, self, other)
# 
#     def __lshift__(self, other):
#         return ArithmeticExpression(operator.lshift, self, other)
# 
#     def __rshift__(self, other):
#         return ArithmeticExpression(operator.rshift, self, other)
# 
# class Constant(Expression):
#     def __init__(self, value):
#         self.value = value
#         
#     def evaluate(self, context):
#         return self.value
# 
#     def __repr__(self):
#         if isinstance(self.value, dt.Data):
#             value = self.value
#             if len(value) % 8:
#                 # We can only convert bytes to hex, so added a '0' data
#                 # object in front.
#                 leading_bits = 8 - len(value) % 8
#                 value = dt.Data('\x00', start=0, end=leading_bits) + value
#             return '0x%s' % value.get_hex()
#         return str(self.value)
# 
# class UndecodedReferenceError(Exception):
#     """
#     Raised when a decoded entry is referenced (but unused).
# 
#     We don't derive this from DecodeError, as it is an internal program error.
#     """
#     def __init__(self, name, context):
#         self.name = name
#         self.context = context
# 
#     def __str__(self):
#         return "Missing context '%s' (have %s)" % (self.name,
#                 ', '.join("'%s'" % k for k in self.context.keys()))


# Path: bdec/entry.py
import operator
import bdec
import bdec.data as dt
from bdec.expression import Expression, Constant, UndecodedReferenceError
        from bdec.spec.references import ReferencedEntry
            from bdec.decode import Decoder
            from bdec.encode import create_encoder

#       * Redistributions in binary form must reproduce the above copyright
#         notice, this list of conditions and the following disclaimer in the
#         documentation and/or other materials provided with the distribution.
#       * Neither the name of the PRESENSE Technologies GmbH nor the
#         names of its contributors may be used to endorse or promote products
#         derived from this software without specific prior written permission.
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#   DISCLAIMED. IN NO EVENT SHALL PRESENSE Technologies GmbH BE LIABLE FOR ANY
#   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
The bdec.entry module defines the core entry class (bdec.entry.Entry) and 
errors (derived from bdec.DecodeError) common to all entry types.
"""



class EntryDataError(bdec.DecodeError):
    """Error raised when an error was found with the entries data.
    
    For example, not enough data was available to decode this entry."""
    def __init__(self, entry, ex):
        bdec.DecodeError.__init__(self, entry)

        self.ex = ex