{"id":205134,"date":"2013-12-06T16:23:06","date_gmt":"2013-12-06T12:23:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=205134"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=205134","title":{"rendered":"<span class=\"post_title\">PyFence: \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f Python<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/instacod.es\/84797\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e92\/c66\/ac2\/e92c66ac2bdb4dc727c3f61db75d189f.png\"\/><\/a><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  <a href=\"http:\/\/eugeny.github.io\/pyfence\/\">PyFence<\/a> \u2014 \u0441\u0430\u043c\u043e\u043f\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. PyFence \u0431\u0435\u0440\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0430\u0445 \u0438\u0437 docstring&#8217;\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 <a href=\"http:\/\/pythonhosted.org\/an_example_pypi_project\/sphinx.html#function-definitions\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Sphinx<\/a>. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f PyFence \u043d\u0435 \u043d\u0443\u0436\u043d\u043e!<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"python\">class RationalFormatter (object):     def format(self, number):         &quot;&quot;&quot;         Stringifies a number to numerator\/denominator format         Example::              &gt;&gt;&gt; print(RationalFormatter().format(1.25))             5\/4          :param number: input number         :type  number: float         :raises      : None         :rtype       : str         &quot;&quot;&quot;         return '%i\/%i' % number.as_integer_ratio()      def display(self, number):         print(str(number) + ' = ' + self.format(number)) <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 <b>format<\/b> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 \u0434\u0440\u043e\u0431\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <b>float.as_integer_ratio()<br \/>  <\/b><br \/>  \u041f\u0440\u043e\u0431\u0443\u0435\u043c:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from formatter import RationalFormatter &gt;&gt;&gt; f = RationalFormatter() &gt;&gt;&gt; f.display(1.25) 1.25 = 5\/4 <\/code><\/pre>\n<p>  \u0412\u0440\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <b>int<\/b>, \u0432\u0435\u0434\u044c <b>int<\/b>, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e,<b> .as_integer_ratio()<\/b> \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442.<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; f.display(5) Traceback (most recent call last):   File &quot;example.py&quot;, line 5, in &lt;module&gt;     f.display(5)   File &quot;\/home\/eugeny\/Work\/pyfence\/example_formatter.py&quot;, line 18, in display     print(str(number) + ' = ' + self.format(number))   File &quot;\/home\/eugeny\/Work\/pyfence\/example_formatter.py&quot;, line 15, in format     return '%i\/%i' % number.as_integer_ratio() AttributeError: 'int' object has no attribute 'as_integer_ratio' <\/code><\/pre>\n<p>  \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 PyFence \u0442\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0440\u0430\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"python\">$ pip install pyfence ... $ fence example.py --fence:strict,stop 1.25 = 5\/4  *** PyFence ERROR ---------------------------  *** PyFence ERROR PyFence verification failed  *** PyFence ERROR  :: example_formatter.RationalFormatter.format(&lt;example_formatter.RationalFormatter object at 0x7ff097a47d10&gt;, 5)  *** PyFence ERROR in example_formatter.py:2  *** PyFence ERROR number was 5 (int) instead of ['float']  *** PyFence ERROR Aborting <\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, PyFence \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445\/\u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c pyfence \u0432 \u0441\u0430\u043c\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 <b>fence<\/b>.<br \/>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c fence \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u0430 \u043d\u0435 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u042f \u0431\u0443\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u043b\u044e\u0431\u043e\u043c\u0443 <a href=\"https:\/\/github.com\/Eugeny\/pyfence\/issues\">\u0444\u0438\u0434\u0431\u0435\u043a\u0443<\/a> \u0438 <a href=\"https:\/\/github.com\/Eugeny\/pyfence\">Pull Request&#8217;\u0430\u043c<\/a>!    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/205134\/\"> http:\/\/habrahabr.ru\/post\/205134\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/instacod.es\/84797\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e92\/c66\/ac2\/e92c66ac2bdb4dc727c3f61db75d189f.png\"\/><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-205134","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/205134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=205134"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/205134\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=205134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=205134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=205134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}