Giter Site home page Giter Site logo

Concerns on encodings about irc HOT 3 CLOSED

jaraco avatar jaraco commented on May 28, 2024
Concerns on encodings

from irc.

Comments (3)

jaraco avatar jaraco commented on May 28, 2024

By default, the IRC library does attempt to decode all incoming streams as UTF-8, but I acknowledge that there are cases where decoding is undesirable or a custom decoding option is desirable. To support these cases, since irc 3.4.2, the ServerConnection class may be customized. The 'buffer_class' attribute on the ServerConnection determines what class is used for buffering lines from the input stream. By default it is DecodingLineBuffer, but may be re-assigned with another class, such as irc.client.LineBuffer, which does not decode the lines and passes them through as byte strings. The 'buffer_class' attribute may be assigned for all instances of ServerConnection by overriding the class attribute::

irc.client.ServerConnection.buffer_class = irc.client.LineBuffer

or it may be overridden on a per-instance basis (as long as it's overridden before the connection is established)::

server = irc.client.IRC().server()
server.buffer_class = irc.client.LineBuffer
server.connect()

I've added a section to the README that documents these options.

Does this interface provide the option you seek? If not, please re-open.


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on May 28, 2024

I've updated the README in https://bitbucket.org/jaraco/irc/changeset/807ab45d31fe to describe the option available to disable/customize encoding.


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on May 28, 2024

Thank you for the reply. It helped me a lot, but I've come up with another problem, mainly because I'm using Python 3.

The library has somewhat mixed uses between bytes and str, and when you convert bytes to str implicitly it would result "b'this'".

We should explicitly choose what to use between two kinds of strings, and I would like to recommend bytes. For example, the channel names are allowed to contain almost any sequences of bytes as specified by RFC 1459, so bytes should be suitable. But when you do that, every line would become problematic:

  • In irc.client.is_channel(): string[0] in "#&+!"
  • In irc.client.ServerConnection.join(): "JOIN %s%s" % (channel, (key and (" " + key)))
  • NickMask(prefix) when a privmsg event has occured

So I'm trying to convert all the internal strings to bytes on my fork, in a similar fashion I've done to irclib: https://github.com/puzzlet/python-irclib


Original comment by: puzzlet

from irc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.