asd
This commit is contained in:
		| @ -0,0 +1 @@ | ||||
| pip | ||||
| @ -0,0 +1,19 @@ | ||||
| Copyright (c) 2015 Marc Brinkmann | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a | ||||
| copy of this software and associated documentation files (the "Software"), | ||||
| to deal in the Software without restriction, including without limitation | ||||
| the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
| and/or sell copies of the Software, and to permit persons to whom the | ||||
| Software is furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in | ||||
| all copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
| DEALINGS IN THE SOFTWARE. | ||||
| @ -0,0 +1,103 @@ | ||||
| Metadata-Version: 2.1 | ||||
| Name: visitor | ||||
| Version: 0.1.3 | ||||
| Summary: A tiny pythonic visitor implementation. | ||||
| Home-page: http://github.com/mbr/visitor | ||||
| Author: Marc Brinkmann | ||||
| Author-email: git@marcbrinkmann.de | ||||
| License: MIT | ||||
| Classifier: Programming Language :: Python :: 2 | ||||
| Classifier: Programming Language :: Python :: 3 | ||||
| License-File: LICENSE | ||||
|  | ||||
| visitor | ||||
| ======= | ||||
|  | ||||
| A tiny library to facilitate `visitor | ||||
| <https://en.wikipedia.org/wiki/Visitor_pattern>`_ implementation in Python | ||||
| (which are slightly peculiar due to dynamic typing). In fact, it is so small, | ||||
| you may just be better off copy & pasting the source straight into your | ||||
| project... | ||||
|  | ||||
|  | ||||
| Example use | ||||
| ----------- | ||||
|  | ||||
| A simple JSON-encoder: | ||||
|  | ||||
| .. code-block:: python | ||||
|  | ||||
|     from visitor import Visitor | ||||
|  | ||||
|  | ||||
|     class JSONEncoder(Visitor): | ||||
|         def __init__(self): | ||||
|             self.indent = 0 | ||||
|  | ||||
|         def escape_str(self, s): | ||||
|             # note: this is not a good escape function, do not use this in | ||||
|             # production! | ||||
|             s = s.replace('\\', '\\\\') | ||||
|             s = s.replace('"', '\\"') | ||||
|             return '"' + s + '"' | ||||
|  | ||||
|         def visit_list(self, node): | ||||
|             self.indent += 1 | ||||
|             s = '[\n' + '  ' * self.indent | ||||
|             s += (',\n' + '  ' * self.indent).join(self.visit(item) | ||||
|                                                    for item in node) | ||||
|             self.indent -= 1 | ||||
|             s += '\n' + '  ' * self.indent + ']' | ||||
|             return s | ||||
|  | ||||
|         def visit_str(self, node): | ||||
|             return self.escape_str(node) | ||||
|  | ||||
|         def visit_int(self, node): | ||||
|             return str(node) | ||||
|  | ||||
|         def visit_bool(self, node): | ||||
|             return 'true' if node else 'false' | ||||
|  | ||||
|         def visit_dict(self, node): | ||||
|             self.indent += 1 | ||||
|             s = '{\n' + '  ' * self.indent | ||||
|             s += (',\n' + '  ' * self.indent).join( | ||||
|                 '{}: {}'.format(self.escape_str(key), self.visit(value)) | ||||
|                 for key, value in sorted(node.items()) | ||||
|             ) | ||||
|             self.indent -= 1 | ||||
|             s += '\n' + '  ' * self.indent + '}' | ||||
|             return s | ||||
|  | ||||
|  | ||||
|     data = [ | ||||
|         'List', 'of', 42, 'items', True, { | ||||
|             'sub1': 'some string', | ||||
|             'sub2': { | ||||
|                 'sub2sub1': False, | ||||
|                 'sub2sub2': 123, | ||||
|             } | ||||
|         } | ||||
|     ] | ||||
|  | ||||
|     print(JSONEncoder().visit(data)) | ||||
|  | ||||
|  | ||||
|  | ||||
| Output:: | ||||
|  | ||||
|     [ | ||||
|       "List", | ||||
|       "of", | ||||
|       42, | ||||
|       "items", | ||||
|       true, | ||||
|       { | ||||
|         "sub1": "some string", | ||||
|         "sub2": { | ||||
|           "sub2sub1": false, | ||||
|           "sub2sub2": 123 | ||||
|         } | ||||
|       } | ||||
|     ] | ||||
| @ -0,0 +1,8 @@ | ||||
| visitor-0.1.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 | ||||
| visitor-0.1.3.dist-info/LICENSE,sha256=GE0eu2Xal62jZEfzwCjy_UiQuHTxexjAI84gDdlmOa8,1058 | ||||
| visitor-0.1.3.dist-info/METADATA,sha256=NgcAhkIjLNmG9mxobLPXaL0nuQGqBcy-9YAMk_5FNQA,2507 | ||||
| visitor-0.1.3.dist-info/RECORD,, | ||||
| visitor-0.1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91 | ||||
| visitor-0.1.3.dist-info/top_level.txt,sha256=YzMUOuikZNH_JrhCf_4ZZFsbtWgkdMoKlTJ4D0CvfP4,8 | ||||
| visitor/__init__.py,sha256=anRPAM2lnPjAly10qb6XaV4hfGZnF1MiE3v6qzRmuyw,2159 | ||||
| visitor/__pycache__/__init__.cpython-312.pyc,, | ||||
| @ -0,0 +1,5 @@ | ||||
| Wheel-Version: 1.0 | ||||
| Generator: setuptools (75.6.0) | ||||
| Root-Is-Purelib: true | ||||
| Tag: py3-none-any | ||||
|  | ||||
| @ -0,0 +1 @@ | ||||
| visitor | ||||
		Reference in New Issue
	
	Block a user