Ejemplo n.º 1
0
#>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#>Let's say you want to 1. monitor and 2. prevent every time something is
#>opening a file:
import pyjack


def fakeopen(orgopen, *args, **kwargs):
    print 'Here is the org open fn: %r' % orgopen
    print 'Someone trying to open a file with args:%r kwargs%r' % (
        args,
        kwargs,
    )
    return ()


pyjack.connect(open, proxyfn=fakeopen)

for line in open('/some/path', 'r'):
    print line


#>Filtering args
#>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def absmin(orgmin, seq):
    return orgmin([abs(x) for x in seq])


pyjack.connect(min, proxyfn=absmin)

print min([-100, 20, -200, 150])
Ejemplo n.º 2
0
    
#>Some examples of connecting to functions
#>------------------------------------------------------------------------------

#>Prevent function from firing
#>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#>Let's say you want to 1. monitor and 2. prevent every time something is 
#>opening a file:
import pyjack

def fakeopen(orgopen, *args, **kwargs):
    print 'Here is the org open fn: %r' % orgopen
    print 'Someone trying to open a file with args:%r kwargs%r' %(args, kwargs,)
    return ()

pyjack.connect(open, proxyfn=fakeopen)

for line in open('/some/path', 'r'):
    print line

#>Filtering args
#>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def absmin(orgmin, seq):
    return orgmin([abs(x) for x in seq])
    
pyjack.connect(min, proxyfn=absmin)

print min([-100, 20, -200, 150])

#>Works across memory space
#>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ejemplo n.º 3
0
        add_autogen=False,
        target='_doctest',
        run_doctest=False,
    )

#>The import:
import pyjack


#>Show the "connect" function:
def fakeimport(orgopen, *args, **kwargs):
    print 'Trying to import %s' % args[0]
    return 'MODULE_%s' % args[0]


pyjack.connect(__import__, proxyfn=fakeimport)

import time
print time

__import__.restore()

import time
print time

#>Show the "replace all refs" function:
item = (100, 'one hundred')
data = {item: True, 'itemdata': item}


class Foobar(object):
Ejemplo n.º 4
0
    import mod2doctest
    mod2doctest.convert(r'C:\Python24\python.exe', src=True,
                        add_autogen=False, target='_doctest',
                        run_doctest=False,)
    


#>The import:
import pyjack

#>Show the "connect" function:
def fakeimport(orgopen, *args, **kwargs):    
    print 'Trying to import %s' % args[0]
    return 'MODULE_%s' % args[0]
    
pyjack.connect(__import__, proxyfn=fakeimport)

import time
print time

__import__.restore()

import time
print time

#>Show the "replace all refs" function:
item = (100, 'one hundred')
data = {item: True, 'itemdata': item}

class Foobar(object):
    the_item = item