Edgewall Software

source: trunk/doc/upgrade.txt

Last change on this file was 1238, checked in by hodgestar, 11 years ago

Updating upgrading document heading.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-rst
File size: 6.5 KB
RevLine 
[829]1================
[292]2Upgrading Genshi
3================
4
[722]5
6.. contents:: Contents
7   :depth: 2
8.. sectnum::
9
[1238]10-------------------------------------------
11Upgrading from Genshi 0.6.x to Genshi 0.7.x
12-------------------------------------------
[722]13
[1238]14Genshi 0.7.x now supports both Python 2 and Python 3.
[1162]15
16The most noticable API change in the Genshi development version is that the
[1161]17default encoding in numerous places is now None (i.e. unicode) instead
18of UTF-8. This change was made in order to ease the transition to Python 3
19where strings are unicode strings by default.
20
21If your application relies on the default UTF-8 encoding a simple way to
[1162]22have it work both with Genshi 0.6.x and the development version is to specify the
[1161]23encoding explicitly in calls to the following classes, methods and functions:
24
25* genshi.HTML
26* genshi.Stream.render
27* genshi.input.HTMLParser
28* genshi.template.MarkupTemplate
29* genshi.template.TemplateLoader
30* genshi.template.TextTemplate (and genshi.template.NewTextTemplate)
31* genshi.template.OldTextTemplate
32
33Whether you explicitly specify UTF-8 or explicitly specify None (unicode) is
34a matter of personal taste, although working with unicode may make porting
35your own application to Python 3 easier.
36
37
[829]38------------------------------------
[882]39Upgrading from Genshi 0.5.x to 0.6.x
40------------------------------------
41
42Required Python Version
43-----------------------
44
45Support for Python 2.3 has been dropped in this release. Python 2.4 is
46now the minimum version of Python required to run Genshi.
47
[1106]48The XPath engine has been completely overhauled for this version. Some
49patterns that previously matched incorrectly will no longer match, and
50the other way around. In such cases, the XPath expressions need to be
51fixed in your application and templates.
[882]52
[1106]53
[882]54------------------------------------
[706]55Upgrading from Genshi 0.4.x to 0.5.x
56------------------------------------
57
[829]58Error Handling
59--------------
[706]60
[722]61The default error handling mode has been changed to "strict". This
62means that accessing variables not defined in the template data will
63now generate an immediate exception, as will accessing object
64attributes or dictionary keys that don't exist. If your templates rely
65on the old lenient behavior, you can configure Genshi to use that
66instead. See the documentation for details on how to do that. But be
67warned that lenient error handling may be removed completely in a
68future release.
[706]69
[829]70Match Template Processing
71-------------------------
72
[810]73There has also been a subtle change to how ``py:match`` templates are
74processed: in previous versions, all match templates would be applied
75to the content generated by the matching template, and only the
76matching template itself was applied recursively to the original
77content. This behavior resulted in problems with many kinds of
78recursive matching, and hence was changed for 0.5: now, all match
79templates declared before the matching template are applied to the
80original content, and match templates declared after the matching
81template are applied to the generated content. This change should not
82have any effect on most applications, but you may want to check your
83use of match templates to make sure.
[722]84
[829]85Text Templates
86--------------
[810]87
[829]88Genshi 0.5 introduces a new, alternative syntax for text templates,
89which is more flexible and powerful compared to the old syntax. For
90backwards compatibility, this new syntax is not used by default,
91though it will be in a future version. It is recommended that you
92migrate to using this new syntax. To do so, simply rename any
93references in your code to ``TextTemplate`` to ``NewTextTemplate``. To
94explicitly use the old syntax, use ``OldTextTemplate`` instead, so
95that you can be sure you'll be using the same language when the
96default in Genshi is changed (at least until the old implementation is
97completely removed).
98
99``Markup`` Constructor
100----------------------
101
[869]102The ``Markup`` class no longer has a specialized constructor. The old
[829]103(undocumented) constructor provided a shorthand for doing positional
104substitutions. If you have code like this:
105
106.. code-block:: python
107
108  Markup('<b>%s</b>', name)
109
[869]110You must replace it by the more explicit:
[829]111
112.. code-block:: python
113
114  Markup('<b>%s</b>') % name
115
[830]116``Template`` Constructor
117------------------------
[829]118
[830]119The constructor of the ``Template`` class and its subclasses has changed
120slightly: instead of the optional ``basedir`` parameter, it now expects
121an (also optional) ``filepath`` parameter, which specifies the absolute
122path to the template. You probably aren't using those constructors
123directly, anyway, but using the ``TemplateLoader`` API instead.
124
125
[829]126------------------------------------
[414]127Upgrading from Genshi 0.3.x to 0.4.x
128------------------------------------
129
[546]130The modules ``genshi.filters`` and ``genshi.template`` have been
131refactored into packages containing multiple modules. While code using
132the regular APIs should continue to work without problems, you should
[722]133make sure to remove any leftover traces of the files ``filters.py``
134and ``template.py`` in the ``genshi`` package on the installation
135path (including the corresponding ``.pyc`` files). This is not
136necessary when Genshi was installed as a Python egg.
[414]137
[421]138Results of evaluating template expressions are no longer implicitly
139called if they are callable. If you have been using that feature, you
140will need to add the parenthesis to actually call the function.
[414]141
[722]142Instances of ``genshi.core.Attrs`` are now immutable. Filters
[503]143manipulating the attributes in a stream may need to be updated. Also,
[722]144the ``Attrs`` class no longer automatically wraps all attribute names
145in ``QName`` objects, so users of the ``Attrs`` class need to do this
146themselves. See the documentation of the ``Attrs`` class for more
[503]147information.
[421]148
[424]149
[829]150---------------------
[292]151Upgrading from Markup
152---------------------
153
154Prior to version 0.3, the name of the Genshi project was "Markup". The
155name change means that you will have to adjust your import statements
156and the namespace URI of XML templates, among other things:
157
[722]158* The package name was changed from "markup" to "genshi". Please
159  adjust any import statements referring to the old package name.
160* The namespace URI for directives in Genshi XML templates has changed
161  from ``http://markup.edgewall.org/`` to
162  ``http://genshi.edgewall.org/``. Please update the ``xmlns:py``
163  declaration in your template files accordingly.
[292]164
165Furthermore, due to the inclusion of a text-based template language,
[722]166the class::
[292]167
[722]168  markup.template.Template
[292]169
[722]170has been renamed to::
[292]171
[722]172  genshi.template.MarkupTemplate
[292]173
174If you've been using the Template class directly, you'll need to
[722]175update your code (a simple find/replace should do—the API itself
[292]176did not change).
Note: See TracBrowser for help on using the repository browser.