Allow the specification of address_family for JSONRPC servers, and
[invirt/packages/python-jsonrpclib.git] / jsonrpclib / config.py
1 import sys
2
3 class LocalClasses(dict):
4     def add(self, cls):
5         self[cls.__name__] = cls
6
7 class Config(object):
8     """
9     This is pretty much used exclusively for the 'jsonclass' 
10     functionality... set use_jsonclass to False to turn it off.
11     You can change serialize_method and ignore_attribute, or use
12     the local_classes.add(class) to include "local" classes.
13     """
14     use_jsonclass = True
15     # Change to False to keep __jsonclass__ entries raw.
16     serialize_method = '_serialize'
17     # The serialize_method should be a string that references the
18     # method on a custom class object which is responsible for 
19     # returning a tuple of the constructor arguments and a dict of
20     # attributes.
21     ignore_attribute = '_ignore'
22     # The ignore attribute should be a string that references the
23     # attribute on a custom class object which holds strings and / or
24     # references of the attributes the class translator should ignore.
25     classes = LocalClasses()
26     # The list of classes to use for jsonclass translation.
27     version = 2.0
28     # Version of the JSON-RPC spec to support
29     user_agent = 'jsonrpclib/0.1 (Python %s)' % \
30         '.'.join([str(ver) for ver in sys.version_info[0:3]])
31     # User agent to use for calls.
32     _instance = None
33     
34     @classmethod
35     def instance(cls):
36         if not cls._instance:
37             cls._instance = cls()
38         return cls._instance