Giter Club home page Giter Club logo

python-iconv's Introduction

Iconv-based codec library for Python

Written by Martin v. Loewis
Ported to Python 3 by Bodo Graumann

This package provides a set of codecs to Python based on the underlying iconv library of the operating system, as available on glibc 2, Solaris, or other Unix variants. It consists of two modules: iconv and iconvcodec. For common usage the codec interface is more convenient and should be preferred.

Installation

To install the module use

pip install python-iconv

This module package requires atleast Python 3.6.

Module iconv

The iconv module exposes a global function to create iconv objects:

open(tocode, fromcode)

Return descriptor for character set conversion. If the conversion of fromcode to tocode is not known to the system, a ValueError is raised.

Iconv objects provide a single method to convert a string

iconv(in[, outlen[, count_only]])

Return the string resulting from the conversion of in. The parameter in must be a byte string. It is the caller's responsibility to guarantee that the internal representation of the in object indeed uses fromcode of the Iconv object. The parameter outlen represents an estimate of the resulting string size in bytes. If the buffer is to small, an exception is thrown. If count_only is set, no conversion is attempted, but the number of necessary bytes is returned.

In case of an error, the iconv method raises the exception iconv.error. This exception has four arguments:

  • the error string as returned from strerror
  • the error number
  • the number of input bytes processed
  • the output string produced so far

Module iconvcodecs

This module encapsulates the iconv module into a set of codecs. To use it, simply import it. As a result, the C library's codecs will be available:

b"Hello".decode("T.61")
"World".encode("JOHAB")

Contributing

Contributions are always welcome. Setting up a local dev environment is as simple as:

python -m venv env
source env/bin/activate
pip install -e .
python -m unittest

Code should be auto-formatted with black.

pip install black
black *.py

Publishing

We currently only publish source distributions.

pip install twine
python setup.py sdist
twine upload dist/*

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

Author

Bodo Graumann [email protected]

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.