Package cssutils :: Module codec |
[hide private]
[frames] | no frames]

# Module codec

source code

Python codec for CSS.

Version: $Id: util.py 1114 2008-03-05 13:22:59Z cthedot $

Author: Walter Doerwald

Classes | [hide private]
| IncrementalDecoder
| IncrementalEncoder
| StreamWriter
| StreamReader
| UTF8SigStreamWriter
| UTF8SigStreamReader

Functions | [hide private]
detectencoding_str(input, final=False) Detect the encoding of the byte string `input`, which contains the beginning of a CSS file. | source code
detectencoding_unicode(input, final=False) Detect the encoding of the unicode string `input`, which contains the beginning of a CSS file. | source code
_fixencoding(input, encoding, final=False) Replace the name of the encoding in the charset rule at the beginning of `input` with `encoding`. | source code
decode(input, errors=`'``strict``'`, encoding=None, force=True) | source code
encode(input, errors=`'``strict``'`, encoding=None) | source code
_bytes2int(bytes) | source code
_int2bytes(i) | source code
utf8sig_encode(input, errors='strict') | source code
utf8sig_decode(input, errors='strict') | source code
search_function(name) | source code
cssescape(exc) | source code

Imports: codecs, marshal

Function Details | [hide private]

### detectencoding_str(input, final=False) | source code
Detect the encoding of the byte string `input`, which contains the beginning of a CSS file. This function returs the detected encoding (or `None` if it hasn't got enough data), and a flag that indicates whether to encoding has been detected explicitely or implicitely. To detect the encoding the first few bytes are used (or if `input` is ASCII compatible and starts with a charset rule the encoding name from the rule). "Explicit" detection means that the bytes start with a BOM or a charset rule. If the encoding can't be detected yet, `None` is returned as the encoding. `final` specifies whether more data is available in later calls or not. If `final` is true, `detectencoding_str()` will never return `None` as the encoding.

### detectencoding_unicode(input, final=False) | source code
Detect the encoding of the unicode string `input`, which contains the beginning of a CSS file. The encoding is detected from the charset rule at the beginning of `input`. If there is no charset rule, `"utf-8"` will be returned. If the encoding can't be detected yet, `None` is returned. `final` specifies whether more data will be available in later calls or not. If `final` is true, `detectencoding_unicode()` will never return `None`.

### _fixencoding(input, encoding, final=False) | source code
Replace the name of the encoding in the charset rule at the beginning of `input` with `encoding`. If `input` doesn't starts with a charset rule, `input` will be returned unmodified. If the encoding can't be found yet, `None` is returned. `final` specifies whether more data will be available in later calls or not. If `final` is true, `_fixencoding()` will never return `None`.