File: __init__.py

package info (click to toggle)
wxwidgets2.8 2.8.12.1-12
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 242,920 kB
  • sloc: cpp: 1,840,772; xml: 385,749; python: 334,729; makefile: 51,774; ansic: 30,987; sh: 7,716; sql: 258; lex: 194; perl: 139; yacc: 128; pascal: 95; php: 45; lisp: 38; tcl: 38; java: 22; haskell: 20; cs: 18; erlang: 17; ruby: 16; asm: 15; ada: 9; ml: 9; csh: 9
file content (76 lines) | stat: -rw-r--r-- 2,792 bytes parent folder | download
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
'''
Core package of pubsub, holding the publisher, listener, and topic
object modules. Functions defined here are used internally by
pubsub so that the right modules can be found later, based on the
selected messaging protocol.

Indeed some of the API depends on the messaging
protocol used. For instance sendMessage(), defined in publisher.py,
has a different signature (and hence implementation) for the kwargs
protocol than for the arg1 protocol.

The most convenient way to
support this is to put the parts of the package that differ based
on protocol in separate folders, and add one of those folders to
the package's __path__ variable (defined automatically by the Python
interpreter when __init__.py is executed). For instance, code
specific to the kwargs protocol goes in the kwargs folder, and code
specific to the arg1 protocol in the arg1 folder. Then when doing
"from pubsub.core import listener", the correct listener.py will be
found for the specified protocol. The default protocol is kwargs.

Only one protocol can be used in an application. The default protocol,
if none is chosen by user, is kwargs, as selected by the call to
_prependModulePath() at end of this file. 

:copyright: Copyright 2006-2009 by Oliver Schoenborn, all rights reserved.
:license: BSD, see LICENSE.txt for details.

'''


def setMsgProtocol(protocol):
    import policies

    policies.msgDataProtocol = protocol

    # add appropriate subdir for protocol-specific implementation
    if protocol == 'kwargs':
        _replaceModulePath0('kwargs')
    else:
        _replaceModulePath0('arg1')


def setMsgDataArgName(stage, listenerArgName, senderArgNameAny=False):
    import policies
    policies.senderKwargNameAny = senderArgNameAny
    policies.msgDataArgName = listenerArgName
    policies.msgProtocolTransStage = stage
    #print `policies.msgProtocolTransStage`, `policies.msgDataProtocol`, \
    #      `policies.senderKwargNameAny`, `policies.msgDataArgName`
    #print 'override "arg1" protocol arg name:', argName


def _replaceModulePath0(dirname):
    '''Replace the first package-path item (in __path__) with dirname.
    The dirname will be prepended with the package's path, assumed to
    be the last item in __path__.'''
    corepath = __path__
    assert len(corepath) > 1
    initpyLoc = corepath[-1]
    import os
    corepath[0] = os.path.join(initpyLoc, dirname)


def _prependModulePath(extra):
    '''Insert extra at beginning of package's path list. Should only be
    called once, at package load time, to set the folder used for
    implementation specific to the default message protocol.'''
    corepath = __path__
    initpyLoc = corepath[-1]
    import os
    corepath.insert(0, os.path.join(initpyLoc, extra))
    

# default protocol:
_prependModulePath('kwargs')