Deserialize a byte string into a BlockWrapper

        Args:
            value (bytes): the byte string to deserialze

        Returns:
            BlockWrapper: a block wrapper instance
174116
def deserialize_block(value):
        
        # Block id strings are stored under batch/txn ids for reference.
        # Only Blocks, not ids or Nones, should be returned by _get_block.
        block = Block()
        block.ParseFromString(value)
        return BlockWrapper(
            block=block)
678591
def wrap_value(value, include_empty=False):
    

    if value is None:
        return [None] if include_empty else []
    elif hasattr(value, '__len__') and len(value) == 0:
        return [value] if include_empty else []
    elif isinstance(value, _wrap_types):
        return [value]
    elif not hasattr(value, '__iter__'):
        return [value]

    return value if include_empty else filter_empty(value, [])
460844
def _decode(self, value):
        
        if isinstance(value, list):
            return [self._decode(v) for v in value]
        elif isinstance(value, dict):
            return {self._decode(k): self._decode(v)
                    for k, v in value.items()}
        elif isinstance(value, bytes):
            return value.decode('utf-8')
        return value
411594
def unwrap(value):
    
    if isinstance(value, Document):
        return value.to_dict()
    elif isinstance(value, DocumentList):
        return value.to_list()
    else:
        return value
59463
def to_bytes(value):
    
    vtype = type(value)

    if vtype == bytes or vtype == type(None):
        return value

    try:
        return vtype.encode(value)
    except UnicodeEncodeError:
        pass
    return value
1139759
def setwrap(value: Any) -> Set[str]:
    
    return set(map(str, set(flatten([value]))))
739016
def data(self, value):
        
        if value is not None and not isinstance(value, unicode):
            value = value.decode('utf-8')
        self._data = value
401611
def wrap(self, value):
        ''' 
        '''
        self.validate_wrap(value)
        ret = []
        for field, value in izip(self.types, value):
            ret.append(field.wrap(value))
        return ret
1195536
def encode(self, value):
        
        if self.decode_responses and isinstance(value, bytes):
            value = value.decode(self.encoding)
        elif not self.decode_responses and isinstance(value, str):
            value = value.encode(self.encoding)
        return value
593476
def block1(self, value):
        
        option = Option()
        option.number = defines.OptionRegistry.BLOCK1.number
        num, m, size = value
        if size > 512:
            szx = 6
        elif 256 < size <= 512:
            szx = 5
        elif 128 < size <= 256:
            szx = 4
        elif 64 < size <= 128:
            szx = 3
        elif 32 < size <= 64:
            szx = 2
        elif 16 < size <= 32:
            szx = 1
        else:
            szx = 0

        value = (num << 4)
        value |= (m << 3)
        value |= szx

        option.value = value
        self.add_option(option)
780341
def _deserialize(type, value)
      case type.to_sym
      when :DateTime
        DateTime.parse(value)
      when :Date
        Date.parse(value)
      when :String
        value.to_s
      when :Integer
        value.to_i
      when :Float
        value.to_f
      when :BOOLEAN
        if value.to_s =~ /\A(true|t|yes|y|1)\z/i
          true
        else
          false
        end
      when :Object
        # generic object (usually a Hash), return directly
        value
      when /\AArray<(?<inner_type>.+)>\z/
        inner_type = Regexp.last_match[:inner_type]
        value.map { |v| _deserialize(inner_type, v) }
      when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
        k_type = Regexp.last_match[:k_type]
        v_type = Regexp.last_match[:v_type]
        {}.tap do |hash|
          value.each do |k, v|
            hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
          end
        end
      else # model
        temp_model = TelestreamCloud::Qc.const_get(type).new
        temp_model.build_from_hash(value)
      end
    end
730238
def encode_value(value, flags=None, base64=False):
    
    if flags:
        # still a no-operation
        logger.debug("Flag %s encoding not implemented yet" % flags)
    if not isinstance(value, bytes):
        raise ValueError("value must be bytes")
    return b64encode(value) if base64 else value
371527
def framers(self, value):
        

        # Handle sequence values
        if isinstance(value, collections.Sequence):
            if len(value) != 2:
                raise ValueError('need exactly 2 values to unpack')
            elif (not isinstance(value[0], framers.Framer) or
                  not isinstance(value[1], framers.Framer)):
                raise ValueError("framer must be an instance of "
                                 "tendril.Framer")

            self._send_framer, self._recv_framer = value

        # If we have a single value, assume it's a framer
        else:
            if not isinstance(value, framers.Framer):
                raise ValueError("framer must be an instance of "
                                 "tendril.Framer")

            self._send_framer = value
            self._recv_framer = value
228399
def from_string(value):
        
        if value == None or len(value) == 0:
            return None
                
        tokens = value.split(":")
        if len(tokens) != 5:
            raise ConfigException(
                None, "BAD_DESCRIPTOR", "Descriptor " + str(value) + " is in wrong format"
            ).with_details("descriptor", value)
            
        return Descriptor(tokens[0].strip(), tokens[1].strip(), tokens[2].strip(), tokens[3].strip(), tokens[4].strip())
1074596
def wrap(self, value):
        ''' '''
        self.validate_wrap(value)
        return self.type.wrap(value)
991002
def _wrap(self, value):
        
        if isinstance(value, dict):
            if any(isinstance(name, int) for name in value.keys()):
                if not all(isinstance(name, int) for name in value.keys()):
                    raise RuntimeError("Integer and non-integer keys: %r"
                                       % value.keys())
                items = sorted(value.iteritems(), key=itemgetter(0))
                return [self._wrap(val) for _, val in items]
            else:
                return Arguments(value)
        elif isinstance(value, list):
            return [self._wrap(x) for x in value]
        else:
            return value
1032055
def wrap(value):
    
    if isinstance(value, Document) or isinstance(value, DocumentList):
        return value
    elif isinstance(value, dict):
        return Document(value)
    elif isinstance(value, list):
        return DocumentList(value)
    else:
        return value