# Path: kitty/model/low_level/encoder.py
# def strToBytes(value):
#     '''
#     :type value: ``str``
#     :param value: value to encode
#     '''
#     kassert.is_of_types(value, (bytes, bytearray, six.string_types))
#     if isinstance(value, six.string_types):
#         return bytes(bytearray([ord(x) for x in value]))
#     elif isinstance(value, bytearray):
#         return bytes(value)
#     return value


import copy
import six
from kitty.core import KittyException, khash
from kitty.model.low_level.encoder import strToBytes

    def __init__(self, field, comp_type, comp_value):
        '''
        :param field: (name of) field that should meet the condition
        :param comp_type: how to compare the values. One of ('>', '<', '>=', '<=', '==', '!=')
        :param comp_value: value to compare the field to

        :example:

            Render the content of the `If` container only if the value
            in the field called "name" is not 'kitty'

            ::

                Template([
                    String('kitty', name='name'),
                    If(Compare('name', '!=', 'kitty'), [
                        String('current name is not kitty')
                    ])
                ])
        '''
        super(Compare, self).__init__(field=field)
        self._comp_type = comp_type
        if comp_type in Compare._comparison_types:
            if comp_type not in ['==', '!='] and isinstance(comp_value, str):
                raise KittyException('can\'t use comparison type "%s" with comparison value of type str' % comp_type)
            self._comp_fn = Compare._comparison_types[comp_type]
        else:
            raise KittyException('unknown comparison type (%s)' % (comp_type))
        if isinstance(comp_value, six.string_types):

# Path: kitty/model/low_level/encoder.py
# def strToBytes(value):
#     '''
#     :type value: ``str``
#     :param value: value to encode
#     '''
#     kassert.is_of_types(value, (bytes, bytearray, six.string_types))
#     if isinstance(value, six.string_types):
#         return bytes(bytearray([ord(x) for x in value]))
#     elif isinstance(value, bytearray):
#         return bytes(value)
#     return value


# Path: kitty/model/low_level/condition.py
import copy
import six
from kitty.core import KittyException, khash
from kitty.model.low_level.encoder import strToBytes


    def __init__(self, field, comp_type, comp_value):
        '''
        :param field: (name of) field that should meet the condition
        :param comp_type: how to compare the values. One of ('>', '<', '>=', '<=', '==', '!=')
        :param comp_value: value to compare the field to

        :example:

            Render the content of the `If` container only if the value
            in the field called "name" is not 'kitty'

            ::

                Template([
                    String('kitty', name='name'),
                    If(Compare('name', '!=', 'kitty'), [
                        String('current name is not kitty')
                    ])
                ])
        '''
        super(Compare, self).__init__(field=field)
        self._comp_type = comp_type
        if comp_type in Compare._comparison_types:
            if comp_type not in ['==', '!='] and isinstance(comp_value, str):
                raise KittyException('can\'t use comparison type "%s" with comparison value of type str' % comp_type)
            self._comp_fn = Compare._comparison_types[comp_type]
        else:
            raise KittyException('unknown comparison type (%s)' % (comp_type))
        if isinstance(comp_value, six.string_types):

            comp_value = strToBytes(comp_value)