This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A tiny library to facilitate visitor 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:

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
    }
  }
]
Release History

Release History

0.1.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.dev1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
visitor-0.1.3.tar.gz (3.3 kB) Copy SHA256 Checksum SHA256 Source May 18, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting