1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
#
# AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: 0\n"
"POT-Creation-Date: 2018-05-14 18:03-0500\n"
"PO-Revision-Date: 2018-05-14 18:03-0500\n"
"Last-Translator: Automatically generated\n"
"Language-Team: None\n"
"MIME-Version: 1.0\n"
"Content-Type: application/x-publican; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Tag: title
#, no-c-format
msgid "Python Coding Guidelines"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<anchor id=\"ch-python-coding\" xreflabel=\"Chapter 3, Python Coding Guidelines\"></anchor>"
msgstr ""
#. Tag: title
#, no-c-format
msgid "Python Boilerplate"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<indexterm> <primary>Python</primary><secondary>boilerplate</secondary> </indexterm> <indexterm> <primary>boilerplate</primary> </indexterm> <indexterm> <primary>licensing</primary><secondary>Python boilerplate</secondary> </indexterm> <indexterm> <primary>Python boilerplate</primary> </indexterm>"
msgstr ""
#. Tag: para
#, no-c-format
msgid "If a Python file is meant to be executed (as opposed to imported), it should have a <literal>.in</literal> extension, and its first line should be:"
msgstr ""
#. Tag: screen
#, no-c-format
msgid "#!@PYTHON@"
msgstr ""
#. Tag: para
#, no-c-format
msgid "which will be replaced with the appropriate python executable when Pacemaker is built. To make that happen, add an AC_CONFIG_FILES() line to configure.ac, and add the file name without .in to .gitignore (see existing examples)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "After the above line if any, every Python file should start like this:"
msgstr ""
#. Tag: programlisting
#, no-c-format
msgid "\"\"\" <BRIEF-DESCRIPTION>\n"
"\"\"\"\n"
"\n"
"# Pacemaker targets compatibility with Python 2.7 and 3.2+\n"
"from __future__ import print_function, unicode_literals, absolute_import, division\n"
"\n"
"__copyright__ = \"Copyright <YYYY[-YYYY]> Andrew Beekhof <andrew@beekhof.net>\"\n"
"__license__ = \"<LICENSE> WITHOUT ANY WARRANTY\""
msgstr ""
#. Tag: para
#, no-c-format
msgid "If the file is meant to be directly executed, the first line (<literal><SHEBANG></literal>) should be <literal>#!/usr/bin/python</literal>. If it is meant to be imported, omit this line."
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal><BRIEF-DESCRIPTION></literal> is obviously a brief description of the file’s purpose. The string may contain any other information typically used in a Python file <ulink url=\"https://www.python.org/dev/peps/pep-0257/\">docstring</ulink>."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>import</literal> statement is discussed further in <xref linkend=\"s-python-future-imports\" />."
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal><YYYY></literal> is the year the code was <emphasis>originally</emphasis> created. <footnote><para> See the U.S. Copyright Office’s <ulink url=\"https://www.copyright.gov/comp3/\">\"Compendium of U.S. Copyright Office Practices\"</ulink>, particularly \"Chapter 2200: Notice of Copyright\", sections 2205.1(A) and 2205.1(F), or <ulink url=\"https://techwhirl.com/updating-copyright-notices/\">\"Updating Copyright Notices\"</ulink> for a more readable summary. </para></footnote> If the code is modified in later years, add <literal>-YYYY</literal> with the most recent year of modification."
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal><LICENSE></literal> should follow the policy set forth in the <ulink url=\"https://github.com/ClusterLabs/pacemaker/blob/master/COPYING\"><literal>COPYING</literal></ulink> file, generally one of \"GNU General Public License version 2 or later (GPLv2+)\" or \"GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)\"."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Python Compatibility"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<indexterm> <primary>Python</primary><secondary>2</secondary> </indexterm> <indexterm> <primary>2</primary> </indexterm> <indexterm> <primary>Python</primary><secondary>3</secondary> </indexterm> <indexterm> <primary>3</primary> </indexterm> <indexterm> <primary>Python</primary><secondary>versions</secondary> </indexterm> <indexterm> <primary>versions</primary> </indexterm>"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Pacemaker targets compatibility with Python 2.7, and Python 3.2 and later. These versions have added features to be more compatible with each other, allowing us to support both the 2 and 3 series with the same code. It is a good idea to test any changes with both Python 2 and 3."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Python Future Imports"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The future imports used in <xref linkend=\"s-python-boilerplate\" /> mean:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "All print statements must use parentheses, and printing without a newline is accomplished with the <literal>end=' '</literal> parameter rather than a trailing comma."
msgstr ""
#. Tag: para
#, no-c-format
msgid "All string literals will be treated as Unicode (the <literal>u</literal> prefix is unnecessary, and must not be used, because it is not available in Python 3.2)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Local modules must be imported using <literal>from . import</literal> (rather than just <literal>import</literal>). To import one item from a local module, use <literal>from .modulename import</literal> (rather than <literal>from modulename import</literal>)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Division using <literal>/</literal> will always return a floating-point result (use <literal>//</literal> if you want the integer floor instead)."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Other Python Compatibility Requirements"
msgstr ""
#. Tag: para
#, no-c-format
msgid "When specifying an exception variable, always use <literal>as</literal> instead of a comma (e.g. <literal>except Exception as e</literal> or <literal>except (TypeError, IOError) as e</literal>). Use <literal>e.args</literal> to access the error arguments (instead of iterating over or subscripting <literal>e</literal>)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Use <literal>in</literal> (not <literal>has_key()</literal>) to determine if a dictionary has a particular key."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Always use the I/O functions from the <literal>io</literal> module rather than the native I/O functions (e.g. <literal>io.open()</literal> rather than <literal>open()</literal>)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "When opening a file, always use the <literal>t</literal> (text) or <literal>b</literal> (binary) mode flag."
msgstr ""
#. Tag: para
#, no-c-format
msgid "When creating classes, always specify a parent class to ensure that it is a \"new-style\" class (e.g. <literal>class Foo(object):</literal> rather than <literal>class Foo:</literal>)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Be aware of the bytes type added in Python 3. Many places where strings are used in Python 2 use bytes or bytearrays in Python 3 (for example, the pipes used with <literal>subprocess.Popen()</literal>). Code should handle both possibilities."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Be aware that the <literal>items()</literal>, <literal>keys()</literal>, and <literal>values()</literal> methods of dictionaries return lists in Python 2 and views in Python 3. In many case, no special handling is required, but if the code needs to use list methods on the result, cast the result to list first."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Do not raise or catch strings as exceptions (e.g. <literal>raise \"Bad thing\"</literal>)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Do not use the <literal>cmp</literal> parameter of sorting functions (use <literal>key</literal> instead, if needed) or the <literal>__cmp__()</literal> method of classes (implement rich comparison methods such as <literal>__lt__()</literal> instead, if needed)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Do not use the <literal>buffer</literal> type."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Do not use features not available in all targeted Python versions. Common examples include:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>html</literal>, <literal>ipaddress</literal>, and <literal>UserDict</literal> modules"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>subprocess.run()</literal> function"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>subprocess.DEVNULL</literal> constant"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>subprocess</literal> module-specific exceptions"
msgstr ""
#. Tag: title
#, no-c-format
msgid "Python Usages to Avoid"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Avoid the following if possible, otherwise research the compatibility issues involved (hacky workarounds are often available):"
msgstr ""
#. Tag: para
#, no-c-format
msgid "long integers"
msgstr ""
#. Tag: para
#, no-c-format
msgid "octal integer literals"
msgstr ""
#. Tag: para
#, no-c-format
msgid "mixed binary and string data in one data file or variable"
msgstr ""
#. Tag: para
#, no-c-format
msgid "metaclasses"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>locale.strcoll</literal> and <literal>locale.strxfrm</literal>"
msgstr ""
#. Tag: para
#, no-c-format
msgid "the <literal>configparser</literal> and <literal>ConfigParser</literal> modules"
msgstr ""
#. Tag: para
#, no-c-format
msgid "importing compatibility modules such as <literal>six</literal> (so we don’t have to add them to Pacemaker’s dependencies)"
msgstr ""
#. Tag: title
#, no-c-format
msgid "Formatting Python Code"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<indexterm> <primary>Python</primary><secondary>formatting</secondary> </indexterm> <indexterm> <primary>formatting</primary> </indexterm>"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Indentation must be 4 spaces, no tabs."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Do not leave trailing whitespace."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Lines should be no longer than 80 characters unless limiting line length significantly impacts readability. For Python, this limitation is flexible since breaking a line often impacts readability, but definitely keep it under 120 characters."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Where not conflicting with this style guide, it is recommended (but not required) to follow <ulink url=\"https://www.python.org/dev/peps/pep-0008/\">PEP 8</ulink>."
msgstr ""
#. Tag: para
#, no-c-format
msgid "It is recommended (but not required) to format Python code such that <literal>pylint --disable=line-too-long,too-many-lines,too-many-instance-attributes,too-many-arguments,too-many-statements</literal> produces minimal complaints (even better if you don’t need to disable all those checks)."
msgstr ""
|