写作缘由
由于我最近很喜欢学习编程,对于编程中目前接触到的样子最美的语言Python很是喜欢。所以选择了一门名字叫做 “Python编程技术” 的公选课,获得了不少的好课件以及很多有用的示例代码。后面等我考试考的差不多了就可以开始进行深入的学习了。想想真是有点小期待呢
代码翻译
本次公选课的结课作业分四个类别,ABCD四个档次,我作为一个非电子信息类的机械🐶,没必要逞强在这儿给自己增加额外的任务,虽然最后我还是写了一个 GUIofCalculator.py 的文件作为自己的结课作业附件📎了。下面是我这次作业的一些内容,对了。在网上参考Google翻译的时候,我想着就算是抄写, 那我也要留下我的痕迹,所以就在Python官方文档中文站上注册了一个开发者账户,然后翻译了一部分,我抽到的题目是B8
xmlrpc server and client module的部分,内容相当有用,跟我当前从事的服务器有很多重合之处,我打算过阵子先从这个module的源代码读起,好好的学习一下关于服务器运维的知识,就用python做微服务器方向的本命语言好了。前期的LAMP架构毕竟太高深了。能用就行了。后面要深入真的太难了。
翻译内容
21.26. xmlrpc.client — XML-RPC client access
21.26.xmlrpc.client XML_RPC客户端进程
XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a transport. With it, a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data. This module supports writing XML-RPC client code; it handles all the details of translating between conformable Python objects and XML on the wire.
XML-RPC是一种使用通过HTTP传递信息的XML作为传输工具的远程过程调用方法。 通过使用这个模块,客户端可以调用远程服务器上的参数(服务器由URI命名)并返回结构化数据的方法。 此模块支持编写XML-RPC客户端代码; 它还可以处理所有符合Python对象特点的项目和XML之间转换的细节。
Warning The xmlrpc.client module is not secure against maliciously constructed data. If you need to parse untrusted or unauthenticated data see XML vulnerabilities.
警告:xmlrpc.client模块对于恶意构造的数据不安全。 如果需要解析不受信任或未经身份验证的数据,请参阅XML漏洞。
class xmlrpc.client.ServerProxy(uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False, use_builtin_types=False, *, context=None)定义xmlrpc实例的时候内部参数有url,transport,encodeing,verbose,allow_none,use_datatime,use_builtin_types,context,默认参数为(uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False, use_builtin_types=False, *, context=None)
A ServerProxy instance is an object that manages communication with a remote XML-RPC server. The required first argument is a URI (Uniform Resource Indicator), and will normally be the URL of the server. The optional second argument is a transport factory instance; by default it is an internal SafeTransport instance for https: URLs and an internal HTTP Transport instance otherwise. The optional third argument is an encoding, by default UTF-8. The optional fourth argument is a debugging flag.
ServerProxy实例是管理与远程XML-RPC服务器通信的对象。所需的第一个参数是URI(统一资源指示符),通常是服务器的URL。可选的第二个参数是传输协议实例;默认情况下,它是https:URL的内部SafeTransport实例,否则为内部其他的HTTP传输实例。可选的第三个参数是编码方式,默认为UTF-8(UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,又称万国码)。可选的第四个参数是调试标志。
The following parameters govern the use of the returned proxy instance. If allow_none is true, the Python constant None will be translated into XML; the default behaviour is for None to raise a TypeError. This is a commonly-used extension to the XML-RPC specification, but isn’t supported by all clients and servers; see http://ontosys.com/xml-rpc/extensions.php for a description. The use_builtin_types flag can be used to cause date/time values to be presented as datetime.datetime objects and binary data to be presented as bytes objects; this flag is false by default. datetime.datetime, bytes and bytearray objects may be passed to calls. The obsolete use_datetime flag is similar to use_builtin_types but it applies only to date/time values.
以下参数控制返回的代理服务器实例的使用。如果allow_none是true,Python常量None将被转换为XML;此时的python默认行为是由于None而抛出的TypeError。这是对XML-RPC规范的常用扩展,但不是由所有客户端和服务器支持;有关说明,请参阅http://ontosys.com/xml-rpc/extensions.php。
use_builtin_types标志可以用于使日期/时间值作为datetime.datetime对象和二进制数据是字节对象,默认情况下此标志为false。datetime.datetime,bytes和bytearray是对象可以传递给函数调用的方法。过时的use_datetime标志与use_builtin_types类似,但它仅适用于日期或者是时间值。
Both the HTTP and HTTPS transports support the URL syntax extension for HTTP Basic Authentication: http://user:pass@host:port/path. The user:pass portion will be base64-encoded as an HTTP ‘Authorization’ header, and sent to the remote server as part of the connection process when invoking an XML-RPC method. You only need to use this if the remote server requires a Basic Authentication user and password. If an HTTPS URL is provided, context may be ssl.SSLContext and configures the SSL settings of the underlying HTTPS connection.
HTTP和HTTPS传输都支持基于HTTP的基本身份验证的URL语法扩展: http://user:pass@host:port/path。 user:pass 部分将被基于base64的方式编码为HTTP“授权”头文件,并在调用XML-RPC方法时作为连接过程的一部分发送到远程服务器。 如果远程服务器需要基本身份验证用户和密码,则只需使用此选项。 如果提供了HTTPS URL,则上下文可能为ssl.SSLContext,并且配置底层为HTTPS连接的SSL设置。
The returned instance is a proxy object with methods that can be used to invoke corresponding RPC calls on the remote server. If the remote server supports the introspection API, the proxy can also be used to query the remote server for the methods it supports (service discovery) and fetch other server-associated metadata.
Types that are conformable (e.g. that can be marshalled through XML), include the following (and except where noted, they are unmarshalled as the same Python type):
返回的实例是一个代理对象,其方法可用于调用远程服务器上的相对应的RPC调用服务。 如果远程服务器支持自检API,那么代理还可以用于向远程服务器查询其支持的方法(服务发现)和获取其他与服务器关联的元数据。
符合的类型(例如,可以通过XML编组),包括以下(除非另有说明,它们被解组为同一个Python类型):
This is the full set of data types supported by XML-RPC. Method calls may also raise a special Fault instance, used to signal XML-RPC server errors, or ProtocolError used to signal an error in the HTTP/HTTPS transport layer. Both Fault and ProtocolError derive from a base class called Error. Note that the xmlrpc client module currently does not marshal instances of subclasses of built-in types.
When passing strings, characters special to XML such as <, >, and & will be automatically escaped. However, it’s the caller’s responsibility to ensure that the string is free of characters that aren’t allowed in XML, such as the control characters with ASCII values between 0 and 31 (except, of course, tab, newline and carriage return); failing to do this will result in an XML-RPC request that isn’t well-formed XML. If you have to pass arbitrary bytes via XML-RPC, use bytes or bytearray classes or the Binary wrapper class described below.
Server is retained as an alias for ServerProxy for backwards compatibility. New code should use ServerProxy.
Changed in version 3.5: Added the context argument.
这是XML-RPC支持的全部数据类型。方法调用也可能产生一个特殊的Fault实例,这一实例用于发信号通知XML-RPC服务器所发生的错误,或者使用ProtocolError来通知HTTP/HTTPS传输层中发生的错误。 Fault和ProtocolError都派生自一个名为Error的基类。请注意,xmlrpc客户端模块当前不封送内置类型的子类的实例。
当传递字符串时,将XML中特殊的的字符转义(如<,>和>)自动转义。但是,调用者有责任确保字符串中没有XML中不允许使用的字符,例如ASCII值在0到31之间的控制字符(当然tab,换行符和回车符这几个除外)。如果做不到上述要求,XML-RPC请求不是格式良好的XML。如果您必须通过XML-RPC传递任意字节,请使用字节或bytearray类或下面描述的Binary wrapper类。
服务器作为ServerProxy的别名保留以实现向后兼容性。新代码应该使用ServerProxy。
在版本3.5中更改:添加上下文参数。
See also
XML-RPC HOWTO
A good description of XML-RPC operation and client software in several languages. Contains pretty much everything an XML-RPC client developer needs to know.
XML-RPC Introspection
Describes the XML-RPC protocol extension for introspection.
XML-RPC Specification
The official specification.
Unofficial XML-RPC Errata Fredrik Lundh’s “unofficial errata, intended to clarify certain details in the XML-RPC specification, as well as hint at ‘best practices’ to use when designing your own XML-RPC implementations.”
另外XML内部有一些注意事项:
XML-RPC HOWTO
XML-RPC操作和客户端软件在几种语言的良好描述。 包含XML-RPC客户端开发人员需要知道的几乎所有内容。
XML-RPC内省
描述用于内省的XML-RPC协议扩展。
XML-RPC规范
官方规格。
非正式XML-RPC错误
Fredrik Lundh的“非官方勘误,旨在澄清XML-RPC规范中的某些细节,以及在设计自己的XML-RPC实现时使用”最佳实践“的提示。