Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why don Twisteds network methods support Unicode objects as well as strings?

0
Posted

Why don Twisteds network methods support Unicode objects as well as strings?

0

In general, such methods (e.g. FileDescriptor’s write) are designed to send bytes over the network. These methods use non-Unicode string objects as a container for the bytes that they send and receive. Unicode objects are not byte-based and are an abstraction used for representing strings of human readable text. In order to send Unicode strings using these methods, you should explicitly specify a byte-based encoding for them, for example: s.encode(“utf-8”) and explicitly decode them at the receiving end. Twisted cannot choose an encoding for you at this level: your encoding choice will be protocol specific and may need to be specified in the message you send (for example, HTTP headers include a encoding specification). For a more complete discussion of the distinction between Unicode strings and specific encodings of Unicode strings, see the following articles: • Glyph’s Implicit encoding is bad example • Dan Sugalski’s What the heck is: A string; • Joel Spolsky’s The Absolute Minimum

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123