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