.. module:: cssutils.serialize

.. index::
    single: ser, cssutils.ser
    object: cssutils.ser

===============
serializing CSS
===============

``CSSSerializer``
=================
There is a single global serializer used throughout the library. You may configure it by setting specific Preferences_ or completely replace it with your own.

A custom serializer must implement all methods the default one provides. Easiest would be to subclass :class:`cssutils.serialize.CSSSerializer`.

To set a new serializer, use::

    sheet = CSSStyleSheet()
    sheet.setSerializer(newser)

You may also set :attr:`cssutils.ser` directly but the above method is the preferred one.

For most cases adjusting the :attr:`cssutils.ser.prefs` of the default serializer should be sufficient though.

.. autoclass:: cssutils.serialize.CSSSerializer


.. _Preferences:

.. index::
    single: cssutils.ser.prefs
    object: cssutils.ser.prefs

``Preferences``
===============
Quite a few preferences of the cssutils serializer may be tweaked.

To set a preference use::

    sheet = CSSStyleSheet()
    sheet.setSerializerPref(pref, value)

You may also set ``cssutils.ser.prefs.PREFNAME = NEWVALUE`` directly.

Preferences are always used *globally*, so for all stylesheets until preferences are set again.


.. autoclass:: cssutils.serialize.Preferences
   :members:
   :inherited-members:

