当前位置: 首页>>代码示例>>Python>>正文


Python Binary.utf8_bytes方法代码示例

本文整理汇总了Python中dNG.data.binary.Binary.utf8_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Binary.utf8_bytes方法的具体用法?Python Binary.utf8_bytes怎么用?Python Binary.utf8_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dNG.data.binary.Binary的用法示例。


在下文中一共展示了Binary.utf8_bytes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: request

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def request(self, method, data = None):
        """
Invoke a given SSDP method on the unicast or multicast recipient.

:param method: HTTP method
:param data: HTTP body

:return: (bool) Request result
:since:  v0.2.00
        """

        if (data is not None): data = Binary.utf8_bytes(data)

        headers = self.headers.copy()

        headers['HOST'] = "{0}:{1:d}".format(self.host, self.port)
        headers['CONTENT-LENGTH'] = (0 if (data is None) else len(data))
        headers['SERVER'] = AbstractSsdp.get_pas_upnp_sddp_identifier_string()

        ssdp_header = "{0} {1} {2}\r\n".format(method.upper(),
                                               self.path,
                                               AbstractSsdp.get_pas_upnp_http_header_string(True)
                                              )

        for header_name in headers:
            if (type(headers[header_name]) is list):
                for header_value in headers[header_name]: ssdp_header += "{0}: {1}\r\n".format(header_name, header_value)
            else: ssdp_header += "{0}: {1}\r\n".format(header_name, headers[header_name])
        #

        ssdp_header = Binary.utf8_bytes("{0}\r\n".format(ssdp_header))

        data = (ssdp_header if (data is None) else ssdp_header + data)
        return self._write_data(data)
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:36,代码来源:abstract_ssdp.py

示例2: send

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def send(self, data = None):
        """
Invoke an SSDP M-SEARCH method on the unicast or multicast recipient.

:return: (bool) Request result
:since:  v0.2.00
        """

        if (data is not None): data = Binary.utf8_bytes(data)

        headers = self.headers.copy()
        headers['CONTENT-LENGTH'] = (0 if (data is None) else len(data))
        headers['SERVER'] = AbstractSsdp.get_pas_upnp_sddp_identifier_string()

        ssdp_header = "{0} {1}\r\n".format(AbstractSsdp.get_pas_upnp_http_header_string(True),
                                           self.http_status
                                          )

        for header_name in headers:
            if (type(headers[header_name]) is list):
                for header_value in headers[header_name]: ssdp_header += "{0}: {1}\r\n".format(header_name, header_value)
            else: ssdp_header += "{0}: {1}\r\n".format(header_name, headers[header_name])
        #

        ssdp_header = Binary.utf8_bytes("{0}\r\n".format(ssdp_header))

        data = (ssdp_header if (data is None) else ssdp_header + data)
        return self._write_data(data)
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:30,代码来源:ssdp_response.py

示例3: _get_blake2_password

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def _get_blake2_password(self, variant, password, username = None):
        """
Returns the BLAKE2 generated password hash.

:param password: User profile password
:param username: User name used while generating BLAKE2 hash

:return: (str) Hash on success; None if not supported
:since:  v0.2.00
        """

        blake2 = None
        blake2_person = None
        blake2_salt = None

        salt = Settings.get("pas_user_profile_password_salt")
        if (salt is None): raise ValueException("User profile password salt is not defined")

        if (variant == PasswordGeneratorsMixin.PASSWORD_TYPE_BLAKE2B):
            blake2 = blake2b
            blake2_salt = Binary.bytes(salt[:blake2b.SALT_SIZE])
            blake2_person = Binary.utf8_bytes(username[:blake2b.PERSON_SIZE])
        #

        if (variant == PasswordGeneratorsMixin.PASSWORD_TYPE_BLAKE2S):
            blake2 = blake2s
            blake2_salt = Binary.bytes(salt[:blake2s.SALT_SIZE])
            blake2_person = Binary.utf8_bytes(username[:blake2s.PERSON_SIZE])
        #

        if (blake2 is None): raise ValueException("BLAKE2 variant given is invalid")

        return blake2(Binary.utf8_bytes(password), salt = blake2_salt, person = blake2_person).hexdigest()
开发者ID:dNG-git,项目名称:pas_user_profile,代码行数:35,代码来源:password_generators_mixin.py

示例4: get_native

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def get_native(native_type, value):
        """
Returns the native value for the given variable definition and UPnP encoded
value.

:param native_type: Native type definition
:param value: Native python value

:return: (str) UPnP encoded value
:since:  v0.2.00
        """

        if (type(native_type) is tuple):
            if (native_type[1] == "xmlns"): _return = value
            elif (native_type[1] == "base64"): _return = Binary.raw_str(b64decode(Binary.utf8_bytes(value)))
            elif (native_type[1] == "date"): _return = RfcBasics.get_iso8601_timestamp(value, has_time = False)
            elif (native_type[1] == "dateTime"): _return = RfcBasics.get_iso8601_timestamp(value, has_timezone = False)
            elif (native_type[1] == "dateTime.tz"): _return = RfcBasics.get_iso8601_timestamp(value)
            elif (native_type[1] == "hex"): _return = Binary.raw_str(unhexlify(Binary.utf8_bytes(value)))
            elif (native_type[1] == "time"): _return = RfcBasics.get_iso8601_timestamp(value, False, has_timezone = False)
            elif (native_type[1] == "time.tz"): _return = RfcBasics.get_iso8601_timestamp(value, False)
            elif (native_type[1] == "uri" and re.match("^\\w+\\:\\w", value) is None): raise ValueException("Given value mismatches defined format for URIs")
            elif (native_type[1] == "uuid" and (not value.startswith("uuid:"))): raise ValueException("Given value mismatches defined format for UUIDs")
            elif (native_type[0] is not str): _return = native_type[0](value)
        elif (native_type is not str): _return = native_type(value)
        else: _return = value

        return _return
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:30,代码来源:variable.py

示例5: handle_result

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def handle_result(self, urn, action, result):
        """
Returns a UPNP response for the given URN and SOAP action.

:param urn: UPnP URN called
:param action: SOAP action called
:param result: UPnP result arguments

:since: v0.2.00
        """

        if (isinstance(result, Exception)):
            if (isinstance(result, UpnpException)): self.send_error(result.get_upnp_code(), "{0:l10n_message}".format(result))
            else: self.send_error(501, L10n.get("errors_core_unknown_error"))
        else:
            xml_resource = XmlResource(node_type = OrderedDict)

            client_settings = self.get_client_settings()
            if (not client_settings.get("upnp_xml_cdata_encoded", False)): xml_resource.set_cdata_encoding(False)

            xml_resource.add_node("s:Envelope", attributes = { "xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/", "s:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/" })

            xml_base_path = "s:Envelope s:Body u:{0}Response".format(action)
            xml_resource.add_node(xml_base_path, attributes = { "xmlns:u": urn })
            xml_resource.set_cached_node(xml_base_path)

            for result_value in result: xml_resource.add_node("{0} {1}".format(xml_base_path, result_value['name']), result_value['value'])

            self.data = Binary.utf8_bytes("<?xml version='1.0' encoding='UTF-8' ?>{0}".format(xml_resource.export_cache(True)))
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:31,代码来源:http_upnp_response.py

示例6: send_error

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def send_error(self, code, description):
        """
Returns a UPNP response for the requested SOAP action.

:param code: UPnP error code
:param description: UPnP error description

:since: v0.2.00
        """

        xml_resource = XmlResource()

        xml_resource.add_node("s:Envelope", attributes = { "xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/", "s:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/" })

        xml_resource.add_node("s:Envelope s:Body s:Fault faultcode", "Client")
        xml_resource.set_cached_node("s:Envelope s:Body")

        xml_resource.add_node("s:Envelope s:Body s:Fault faultstring", "UPnPError")
        xml_resource.add_node("s:Envelope s:Body s:Fault detail UPnPError", attributes = { "xmlns": "urn:schemas-upnp-org:control-1.0" })
        xml_resource.set_cached_node("s:Envelope s:Body s:Fault detail UPnPError")

        xml_resource.add_node("s:Envelope s:Body s:Fault detail UPnPError errorCode", code)
        xml_resource.add_node("s:Envelope s:Body s:Fault detail UPnPError errorDescription", description)

        self.data = Binary.utf8_bytes("<?xml version='1.0' encoding='UTF-8' ?>{0}".format(xml_resource.export_cache(True)))
        self.send()
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:28,代码来源:http_upnp_response.py

示例7: data

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def data(self):
        """
Returns buffered data to be transmitted.

:return: (bytes) Data to be send
:since:  v1.0.0
        """

        return Binary.utf8_bytes(self._data)
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:11,代码来源:http_xhtml_response.py

示例8: get_upnp_value

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def get_upnp_value(variable, value):
        """
Returns a valid UPnP encoded value for the given variable definition and
value.

:param variable: Variable definition
:param value: Native python value

:return: (str) UPnP encoded value
:since:  v0.2.00
        """

        native_type = Variable.get_native_type(variable)

        if (type(native_type) is tuple):
            value_normalized = (Binary.str(value) if (native_type[0] == str) else value)
            value_normalized_type = type(value_normalized)

            if (value_normalized_type != native_type[0]): raise ValueException("Given value mismatches defined format")
            elif (len(native_type) > 2):
                if (native_type[1] != "xmlns"): raise ValueException("Invalid native type definition")
                _return = value_normalized
            elif (len(native_type[1]) > 1):
                if (native_type[1] == "base64"): _return = Binary.str(b64encode(Binary.bytes(value) if (value == value_normalized) else value))
                elif (native_type[1] == "f14.4"): _return = "{0:14.4g}".format(value).strip()
                elif (native_type[1] == "date"): _return = strftime("%Y-%m-%d", localtime(value))
                elif (native_type[1] == "dateTime"): _return = strftime("%Y-%m-%dT%H:%M:%S", localtime(value))
                elif (native_type[1] == "dateTime.tz"): _return = strftime("%Y-%m-%dT%H:%M:%S%Z", localtime(value))
                elif (native_type[1] == "hex"): _return = Binary.str(hexlify(Binary.bytes(value) if (value == value_normalized) else value))
                elif (native_type[1] == "time"): _return = strftime("%H:%M:%S", localtime(value))
                elif (native_type[1] == "time.tz"): _return = strftime("%H:%M:%S%Z", localtime(value))
                elif (native_type[1] == "uri" and len(urlsplit(value).scheme.strip()) < 1): raise ValueException("Given value is not a valid URI")
                elif (native_type[1] == "uuid" and Variable.RE_UUID.match(value_normalized) is None): raise ValueException("Given value is not a valid UUID")
                else: _return = value_normalized
            else:
                pack("={0}".format(native_type[1]),
                                   (Binary.utf8_bytes(value)
                                    if (value_normalized_type == str and value == value_normalized) else
                                    value
                                   )
                                  )

                _return = "{0}".format(value_normalized)
            #
        else:
            if (native_type is str): value = Binary.str(value)
            if (type(value) is not native_type): raise ValueException("Given value mismatches defined format")

            if (native_type is bool): _return = "{0:b}".format(value)
            elif (native_type is int): _return = str(value)
            elif (native_type is float): _return = "{0:f}".format(value)
            else: _return = value
        #

        return _return
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:57,代码来源:variable.py

示例9: _marshal_basic_type_data

# 需要导入模块: from dNG.data.binary import Binary [as 别名]
# 或者: from dNG.data.binary.Binary import utf8_bytes [as 别名]
    def _marshal_basic_type_data(_type, data, is_le = False, offset = 0):
        """
Marshals data of a basic type.

:param _type: D-Bus signature type code (ASCII)
:param data: Wire-formatted data
:param is_le: True if message contains data in little endian byte order
:param position: Current read position in the wire-formatted data

:return: (int) Position matching the given boundary
:since:  v0.2.00
        """

        if (isinstance(data, TypeObject)):
            if (data.get_hint() != _type): raise ValueException("D-Bus basic data type does not match requested data type")
            data = data.get_value()
        #

        data_type = type(data)
        marshaled_data = None
        marshaled_size_data = None

        # "<" little endian, ">" big endian
        pack_spec = ("<" if (is_le) else ">")

        if (_type == "y"):
            if (data_type is int): marshaled_data = pack(pack_spec + "B", data)
            elif (data_type in ( str, Binary.BYTES_TYPE )):
                data = Binary.bytes(data)
                marshaled_data = pack(pack_spec + "c", data)
            #
        elif (_type == "b"):
            if (data_type is int): marshaled_data = pack(pack_spec + "B", data)
            elif (data_type is bool): marshaled_data = pack(pack_spec + "?", data)
        elif (_type == "n"):
            if (data_type is int): marshaled_data = pack(pack_spec + "h", data)
        elif (_type == "q"):
            if (data_type is int): marshaled_data = pack(pack_spec + "H", data)
        elif (_type == "i"):
            if (data_type is int): marshaled_data = pack(pack_spec + "i", data)
        elif (_type == "u"):
            if (data_type is int): marshaled_data = pack(pack_spec + "I", data)
        elif (_type == "x"):
            if (data_type is int): marshaled_data = pack(pack_spec + "q", data)
        elif (_type == "t"):
            if (data_type is int): marshaled_data = pack(pack_spec + "Q", data)
        elif (_type == "d"):
            if (data_type in ( float, int )): marshaled_data = pack(pack_spec + "d", data)
        elif (_type == "h"):
            if (data_type is int): marshaled_data = pack(pack_spec + "I", data)
        elif (_type in ( "s", "o" )):
            if (data_type not in ( str, Binary.BYTES_TYPE )): data = str(data)

            data = Binary.utf8_bytes(data)
            data_length = len(data)

            ( offset, marshaled_size_data ) = Message._marshal_basic_type_data("u", data_length, is_le, offset)
            marshaled_data = pack(pack_spec + "{0:d}sx".format(data_length), data)
        elif (_type == "g"):
            if (data_type in ( str, Binary.BYTES_TYPE )):
                data = Binary.utf8_bytes(data)
                data_length = len(data)

                marshaled_size_data = pack(pack_spec + "B", data_length)
                offset += 1

                marshaled_data = pack(pack_spec + "{0:d}sx".format(data_length), data)
            #
        #

        if (marshaled_data is None): raise ValueException("Data given is invalid for the D-Bus basic type defined")

        return_data = (Binary.BYTES_TYPE() if (marshaled_size_data is None) else marshaled_size_data)

        ( offset, boundary_data ) = Message._get_boundary_data(offset, _type)
        if (len(boundary_data) > 0): return_data += boundary_data

        return_data += marshaled_data
        offset += len(marshaled_data)

        return ( offset, return_data )
开发者ID:dNG-git,项目名称:pas_dbus,代码行数:83,代码来源:message.py


注:本文中的dNG.data.binary.Binary.utf8_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。