Convert the encoded value of component to standard value (WFN value).
975953
def _decode(self):
        

        result = []
        idx = 0
        s = self._encoded_value

        while (idx < len(s)):
            # Get the idx'th character of s
            c = s[idx]

            if (c in CPEComponent2_2.NON_STANDARD_VALUES):
                # Escape character
                result.append("\\")
                result.append(c)
            else:
                # Do nothing
                result.append(c)

            idx += 1

        self._standard_value = "".join(result)
598956
def encode_value_using_ma(message_attribute: int, value: Optional[Union[int, float]]) -> int:
    """"""
    if message_attribute == MA_TX3AC_100A:
        # TX-3AC in 100A mode; use value as-is, with 0xFE indicating null
        if value is None:
            return 0xfe
        return int(value)
    elif message_attribute == MA_TX3AC_10A:
        # TX-3AC in 10A mode; shift decimal point, with 0xFE indicating null
        if value is None:
            return 0xfe
        return int(value * 10)
    else:
        # Signed byte, with 0x80 indicating null
        if value is None:
            return 0x80
        elif value < 0:
            return 0x100 + int(value)
        return int(value)
1024147
def _Encode(self, value):
    """"""
    try:
      return value.SerializeToString().encode("hex")
    except AttributeError:
      if isinstance(value, (int, long)):
        return str(value).encode("hex")
      else:
        # Types "string" and "bytes" are stored as strings here.
        return utils.SmartStr(value).encode("hex")
1353658
def encode(self, value):
        """"""
        if type(value) == str and self.enum and value in self.enum:
            value = self.enum[value]

        if type(value) == int:
            if self.shift > 0:
                value <<= self.shift
            if self.mask is not None:
                value &= self.mask

        return self.type.encode(value) if self.type else bytearray()
993226
private byte[] berEncodedValue() {
        final ByteBuffer buff = ByteBuffer.allocate(5);
        buff.put((byte) 0x30); // (Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
        buff.put((byte) 0x03); // size
        buff.put((byte) 0x02); // 4bytes int tag
        buff.put((byte) 0x01); // int size
        buff.put(NumberFacility.leftTrim(NumberFacility.getBytes(flags))); // value
        return buff.array();
    }
957930
def _encode(cls, value):
        """"""

        value = json.dumps(value)
        return cls._ENC_RE.sub(lambda x: '%%%2x' % ord(x.group(0)), value)
522677
def encode(value, encoding='utf-8', encoding_errors='strict'):
    
    if isinstance(value, bytes):
        return value
    if not isinstance(value, basestring):
        value = str(value)
    if isinstance(value, unicode):
        value = value.encode(encoding, encoding_errors)
    return value
963731
def parse_value(self, sn: "DataNode") -> ScalarValue:
        """"""
        res = sn.type.parse_value(self.value)
        if res is None:
            raise InvalidKeyValue(self.value)
        return res
445231
function convertViewportValue(value) {
            var mask = /^(\d+)x(\d+)$/,
                matches;
            if (isString(value) && mask.test(value)) {
                matches = value.match(mask);
                return {
                    width: toInteger(matches[1]),
                    height: toInteger(matches[2])
                };
            } else if (isRegularObject(value) &&
                value.hasOwnProperty("width") && (value.width >= 1) &&
                value.hasOwnProperty("height") && (value.height >= 1)
            ) {
                return {
                    width: toInteger(value.width),
                    height: toInteger(value.height)
                };
            } else {
                return undefined;
            }
        }
309485
function apivalueFromValue(value) {
  const composedValue = (componentKind) => {
    const elements = value[componentKind].map((it) => {
      const apiValue = apivalueFromValue(it);
      const value = apiValue && apiValue.value;

      return value;
    });

    return {
      type: value.type().toString(),
      value: elements
    };
  };

  if (value === null) {
    return null;
  }
  if (value.isInteger()) {
    return {
      type: i18n('TYPE:Integer'),
      value: value.asNumber()
    };
  } else if (value.isBoolean()) {
    return {
      type: i18n('TYPE:Bool'),
      value: boolFromValue(value)
    };
  } else if (value.isString()) {
    return {
      type: i18n('TYPE:String'),
      value: value.string
    };
  } else if (value.isTuple()) {
    return composedValue('components');
  } else if (value.isList()) {
    return composedValue('elements');
  } else if (value.isStructure()) {
    return {
      type: value.typeName,
      value: value.toString()
    };
  } else {
    return {
      type: value.type().toString(),
      value: value.toString()
    };
  }
}
162664
def SignedVarintEncode(value):
  """"""
  result = b""
  if value < 0:
    value += (1 << 64)

  bits = value & 0x7f
  value >>= 7
  while value:
    result += HIGH_CHR_MAP[bits]
    bits = value & 0x7f
    value >>= 7
  result += CHR_MAP[bits]

  return result
742095
def _raw_to_der(self, raw_signature):
        """"""
        component_length = self._sig_component_length()
        if len(raw_signature) != int(2 * component_length):
            raise ValueError("Invalid signature")

        r_bytes = raw_signature[:component_length]
        s_bytes = raw_signature[component_length:]
        r = int_from_bytes(r_bytes, "big")
        s = int_from_bytes(s_bytes, "big")
        return encode_dss_signature(r, s)
981278
def Encode(self, attribute, value):
    """"""
    required_type = self._attribute_types.get(attribute, "bytes")

    if required_type == "integer":
      return rdf_structs.SignedVarintEncode(int(value))
    elif required_type == "unsigned_integer":
      return rdf_structs.VarintEncode(int(value))
    elif hasattr(value, "SerializeToString"):
      return value.SerializeToString()
    elif isinstance(value, bytes):
      return value
    elif isinstance(value, Text):
      return value.encode("utf-8")
    else:
      return str(value).encode("utf-8")
464732
function encodeUriParameterValue(value) {
    return encodeURIComponent(value).
    replace(/%40/gi, '@').
    replace(/%3A/gi, ':').
    replace(/%24/g, '$').
    replace(/%2C/gi, ',').
    replace(/%3B/gi, ';').
    replace(/%20/g, '+');
}
383508
function encodeFloat(value) {
    let buffer = new ByteBuffer();
    buffer.littleEndian = true;
    buffer.limit = 8;
    if (value === null) {
        return buffer;
    }
    return buffer.writeFloat(value);
}
500856
def encode(self, value, length, signed):
        '''
        
        '''
        if signed:
            raise KittyException('Signed MultiBytes not supported yet, sorry')

        # split to septets
        if value:
            bytes_arr = []
            while value:
                bytes_arr.append((value & 0x7f) | 0x80)
                value >>= 7
        else:
            bytes_arr = [0]

        # reverse if big endian endian
        if self._mode == 'be':
            bytes_arr.reverse()

        # remove msb from last byte
        bytes_arr[-1] = bytes_arr[-1] & 0x7f

        multi_bytes = ''.join(chr(x) for x in bytes_arr)
        return Bits(bytes=strToBytes(multi_bytes))
923284
def as_wfn(self):
        

        from .cpe2_3_wfn import CPE2_3_WFN

        wfn = []
        wfn.append(CPE2_3_WFN.CPE_PREFIX)

        for i in range(0, len(CPEComponent.ordered_comp_parts)):
            ck = CPEComponent.ordered_comp_parts[i]
            lc = self._get_attribute_components(ck)

            if len(lc) > 1:
                # Incompatible version 1.1, there are two or more elements
                # in CPE Name
                errmsg = "Incompatible version {0} with WFN".format(
                    self.VERSION)
                raise TypeError(errmsg)

            else:
                comp = lc[0]

                v = []
                v.append(ck)
                v.append("=")

                if isinstance(comp, CPEComponentAnyValue):

                    # Logical value any
                    v.append(CPEComponent2_3_WFN.VALUE_ANY)

                elif isinstance(comp, CPEComponentNotApplicable):

                    # Logical value not applicable
                    v.append(CPEComponent2_3_WFN.VALUE_NA)

                elif (isinstance(comp, CPEComponentUndefined) or
                      isinstance(comp, CPEComponentEmpty)):
                    # Do not set the attribute
                    continue
                else:
                    # Get the simple value of WFN of component
                    v.append('"')
                    v.append(comp.as_wfn())
                    v.append('"')

                # Append v to the WFN and add a separator
                wfn.append("".join(v))
                wfn.append(CPEComponent2_3_WFN.SEPARATOR_COMP)

        # Del the last separator
        wfn = wfn[:-1]

        # Return the WFN string
        wfn.append(CPE2_3_WFN.CPE_SUFFIX)

        return "".join(wfn)