Create a |ASN.1| object initialized from a string of '0' and '1'.

        Parameters
        ----------
        value: :class:`str`
            Text string like '1010111'
965672
def fromBinaryString(value):
        
        bitNo = 8
        byte = 0
        r = []
        for v in value:
            if bitNo:
                bitNo -= 1
            else:
                bitNo = 7
                r.append(byte)
                byte = 0
            if v in ('0', '1'):
                v = int(v)
            else:
                raise error.PyAsn1Error(
                    'Non-binary OCTET STRING initializer %s' % (v,)
                )
            byte |= v << bitNo

        r.append(byte)

        return octets.ints2octs(r)
1362501
def set(self, value):
        

        if not isinstance(value, str_cls):
            raise TypeError(unwrap(
                '''
                %s value must be a unicode string, not %s
                ''',
                type_name(self),
                type_name(value)
            ))

        self._native = value

        if self._map is not None:
            if value in self._reverse_map:
                value = self._reverse_map[value]

        self.contents = b''
        first = None
        for index, part in enumerate(value.split('.')):
            part = int(part)

            # The first two parts are merged into a single byte
            if index == 0:
                first = part
                continue
            elif index == 1:
                part = (first * 40) + part

            encoded_part = chr_cls(0x7F & part)
            part = part >> 7
            while part > 0:
                encoded_part = chr_cls(0x80 | (0x7F & part)) + encoded_part
                part = part >> 7
            self.contents += encoded_part

        self._header = None
        if self._trailer != b'':
            self._trailer = b''
690213
def encode(self, value):
        
        if isinstance(value, Token):
            return b(value.value)        
        if isinstance(value, bytes):
            return value
        elif isinstance(value, (int, long)):
            value = b(str(value))        
        elif isinstance(value, float):
            value = repr(value)
        elif not isinstance(value, basestring):
            value = str(value)
        if isinstance(value, unicode):
            value = value.encode(self.encoding, self.encoding_errors)
        return value
1318627
def encode(cls, value):
        
        try:
            coerced = bytes(value)
            if coerced == value:
                return coerced
        except (TypeError, UnicodeError):
            pass

        raise InvalidValue('not binary')
1286209
def from_value(cls, value, size=None, fmt='Q', **kwargs):
        '''
        
        '''
        bl = cls(**kwargs)  # size is 0 by default
        bl.fromvalue(value=value, size=size, fmt=fmt)
        return bl
1263215
def validate(self, value):
        
        val = value
        if isinstance(val, str):
            #FIXME: unsafe decoding
            val = unicode(value)
        val = super(String, self).validate(val)
        if not isinstance(val, unicode):
            raise ValueError("Not a string: %r" % (value, ))
        return val
317223
def set(self, value):
        

        if not isinstance(value, int_types) and not isinstance(value, str_cls):
            raise TypeError(unwrap(
                '''
                %s value must be an integer or a unicode string, not %s
                ''',
                type_name(self),
                type_name(value)
            ))

        if isinstance(value, str_cls):
            if value not in self._reverse_map:
                raise ValueError(unwrap(
                    '''
                    %s value "%s" is not a valid value
                    ''',
                    type_name(self),
                    value
                ))

            value = self._reverse_map[value]

        elif value not in self._map:
            raise ValueError(unwrap(
                '''
                %s value %s is not a valid value
                ''',
                type_name(self),
                value
            ))

        Integer.set(self, value)
362653
def pack_str(cls, value):
        
        assert isinstance(value, str)
        value_len_packed = cls.pack_int_base128(len(value))
        return struct.pack("<%ds%ds" % (len(value_len_packed), len(value)), value_len_packed,  value)
383828
def to_python(self, value):
        
        if value == "":
            return None

        try:
            if isinstance(value, six.string_types):
                return self.deserializer(value)
            elif isinstance(value, bytes):
                return self.deserializer(value.decode('utf8'))
        except ValueError:
            pass
        return value
1278380
def __type2python(cls, value):
        
        if isinstance(value, string_types):
            if value is 'null':
                return None
            elif value in ('true', 'false'):
                return False if value == 'false' else True
            elif value.replace('.', '', 1).isdigit():
                return eval(value)
            elif value.startswith('{') and value.endswidth('}'):
                try:
                    return json.loads(value)
                except ValueError:
                    return value
        return value
1250686
def to_python(self, value):
        
        if isinstance(value, type(re.compile(''))):
            return value
        else:
            if value is None and self.null:
                return None
            else:
                try:
                    return self.get_compiled_regex(value)
                except:
                    raise ValidationError('Invalid regex {0}'.format(value))
87446
def create_string(value)
      if (values = current_attributes[:values]) &&
        (values = values.sort_by {|e| e.to_s})
          value = auto_alias_value(values, value)
          validate_enum_values(values, value)
      end
      value
    end
632335
def normalize_value(value, snake_case=True):
    
    if not isinstance(value, six.string_types):
        raise TypeError("the value passed to value must be a string")

    if snake_case:
        s1 = first_cap_re.sub(r'\1_\2', value)
        new_value = all_cap_re.sub(r'\1_\2', s1).lower()  # .replace('-', '_')
    else:
        new_value = value.lower()

    return new_value
1190733
def format_arg(value):
    
    translator = repr if isinstance(value, six.string_types) else six.text_type
    return translator(value)
118040
def from_bid(cls, value):
        
        if not isinstance(value, bytes):
            raise TypeError("value must be an instance of bytes")
        if len(value) != 16:
            raise ValueError("value must be exactly 16 bytes")
        return cls((_UNPACK_64(value[8:])[0], _UNPACK_64(value[:8])[0]))
1028090
def decode(value: str) -> Union[str, None, bool, int, float]:
    

    assert value.isdigit() or value[0] == '-' and value[1:].isdigit()

    if -I32_BOUND <= int(value) < I32_BOUND:  # it's an i32: it is its own encoding
        return int(value)
    elif int(value) == I32_BOUND:
        return None

    (prefix, value) = (int(value[0]), int(value[1:]))
    ival = int(value) - I32_BOUND
    if ival == 0:
        return ''  # special case: empty string encodes as 2**31
    elif ival == 1:
        return False  # sentinel for bool False
    elif ival == 2:
        return True  # sentinel for bool True

    blen = ceil(log(ival, 16)/2)
    ibytes = unhexlify(ival.to_bytes(blen, 'big'))
    return DECODE_PREFIX.get(prefix, str)(ibytes.decode())
1028331
def encode(cls, value):
        
        if value not in [True, False]:
            raise InvalidValue('not a boolean')

        return b'1' if value else b''