ShellBanner
System:Linux MiraNet 3.0.0-14-generic-pae #23-Ubuntu SMP Mon Nov 21 22:07:10 UTC 2011 i686
Software:Apache. PHP/5.3.6-13ubuntu3.10
ID:uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Safe Mode:OFF
Open_Basedir:OFF
Freespace:25.77 GB of 70.42 GB (36.59%)
MySQL: ON MSSQL: OFF Oracle: OFF PostgreSQL: OFF Curl: OFF Sockets: ON Fetch: OFF Wget: ON Perl: ON
Disabled Functions: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

/ usr/ share/ pyshared/ twisted/ test/ - drwxr-xr-x

Directory:
Viewing file:     test_explorer.py (6.83 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |

# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


"""
Test cases for explorer
"""

from twisted.trial import unittest

from twisted.manhole import explorer

import types, string

"""
# Tests:

 Get an ObjectLink.  Browse ObjectLink.identifier.  Is it the same?

 Watch Object.  Make sure an ObjectLink is received when:
   Call a method.
   Set an attribute.

 Have an Object with a setattr class.  Watch it.
   Do both the navite setattr and the watcher get called?

 Sequences with circular references.  Does it blow up?
"""

class SomeDohickey:
    def __init__(self, *a):
        self.__dict__['args'] = a

    def bip(self):
        return self.args


class TestBrowser(unittest.TestCase):
    def setUp(self):
        self.pool = explorer.explorerPool
        self.pool.clear()
        self.testThing = ["How many stairs must a man climb down?",
                          SomeDohickey(42)]

    def test_chain(self):
        "Following a chain of Explorers."
        xplorer = self.pool.getExplorer(self.testThing, 'testThing')
        self.failUnlessEqual(xplorer.id, id(self.testThing))
        self.failUnlessEqual(xplorer.identifier, 'testThing')

        dxplorer = xplorer.get_elements()[1]
        self.failUnlessEqual(dxplorer.id, id(self.testThing[1]))

class Watcher:
    zero = 0
    def __init__(self):
        self.links = []

    def receiveBrowserObject(self, olink):
        self.links.append(olink)

    def setZero(self):
        self.zero = len(self.links)

    def len(self):
        return len(self.links) - self.zero


class SetattrDohickey:
    def __setattr__(self, k, v):
        v = list(str(v))
        v.reverse()
        self.__dict__[k] = string.join(v, '')

class MiddleMan(SomeDohickey, SetattrDohickey):
    pass

# class TestWatch(unittest.TestCase):
class FIXME_Watch:
    def setUp(self):
        self.globalNS = globals().copy()
        self.localNS = {}
        self.browser = explorer.ObjectBrowser(self.globalNS, self.localNS)
        self.watcher = Watcher()

    def test_setAttrPlain(self):
        "Triggering a watcher response by setting an attribute."

        testThing = SomeDohickey('pencil')
        self.browser.watchObject(testThing, 'testThing',
                                 self.watcher.receiveBrowserObject)
        self.watcher.setZero()

        testThing.someAttr = 'someValue'

        self.failUnlessEqual(testThing.someAttr, 'someValue')
        self.failUnless(self.watcher.len())
        olink = self.watcher.links[-1]
        self.failUnlessEqual(olink.id, id(testThing))

    def test_setAttrChain(self):
        "Setting an attribute on a watched object that has __setattr__"
        testThing = MiddleMan('pencil')

        self.browser.watchObject(testThing, 'testThing',
                                 self.watcher.receiveBrowserObject)
        self.watcher.setZero()

        testThing.someAttr = 'ZORT'

        self.failUnlessEqual(testThing.someAttr, 'TROZ')
        self.failUnless(self.watcher.len())
        olink = self.watcher.links[-1]
        self.failUnlessEqual(olink.id, id(testThing))


    def test_method(self):
        "Triggering a watcher response by invoking a method."

        for testThing in (SomeDohickey('pencil'), MiddleMan('pencil')):
            self.browser.watchObject(testThing, 'testThing',
                                     self.watcher.receiveBrowserObject)
            self.watcher.setZero()

            rval = testThing.bip()
            self.failUnlessEqual(rval, ('pencil',))

            self.failUnless(self.watcher.len())
            olink = self.watcher.links[-1]
            self.failUnlessEqual(olink.id, id(testThing))


def function_noArgs():
    "A function which accepts no arguments at all."
    return

def function_simple(a, b, c):
    "A function which accepts several arguments."
    return a, b, c

def function_variable(*a, **kw):
    "A function which accepts a variable number of args and keywords."
    return a, kw

def function_crazy((alpha, beta), c, d=range(4), **kw):
    "A function with a mad crazy signature."
    return alpha, beta, c, d, kw

class TestBrowseFunction(unittest.TestCase):

    def setUp(self):
        self.pool = explorer.explorerPool
        self.pool.clear()

    def test_sanity(self):
        """Basic checks for browse_function.

        Was the proper type returned?  Does it have the right name and ID?
        """
        for f_name in ('function_noArgs', 'function_simple',
                       'function_variable', 'function_crazy'):
            f = eval(f_name)

            xplorer = self.pool.getExplorer(f, f_name)

            self.failUnlessEqual(xplorer.id, id(f))

            self.failUnless(isinstance(xplorer, explorer.ExplorerFunction))

            self.failUnlessEqual(xplorer.name, f_name)

    def test_signature_noArgs(self):
        """Testing zero-argument function signature.
        """

        xplorer = self.pool.getExplorer(function_noArgs, 'function_noArgs')

        self.failUnlessEqual(len(xplorer.signature), 0)

    def test_signature_simple(self):
        """Testing simple function signature.
        """

        xplorer = self.pool.getExplorer(function_simple, 'function_simple')

        expected_signature = ('a','b','c')

        self.failUnlessEqual(xplorer.signature.name, expected_signature)

    def test_signature_variable(self):
        """Testing variable-argument function signature.
        """

        xplorer = self.pool.getExplorer(function_variable,
                                        'function_variable')

        expected_names = ('a','kw')
        signature = xplorer.signature

        self.failUnlessEqual(signature.name, expected_names)
        self.failUnless(signature.is_varlist(0))
        self.failUnless(signature.is_keyword(1))

    def test_signature_crazy(self):
        """Testing function with crazy signature.
        """
        xplorer = self.pool.getExplorer(function_crazy, 'function_crazy')

        signature = xplorer.signature

        expected_signature = [{'name': 'c'},
                              {'name': 'd',
                               'default': range(4)},
                              {'name': 'kw',
                               'keywords': 1}]

        # The name of the first argument seems to be indecipherable,
        # but make sure it has one (and no default).
        self.failUnless(signature.get_name(0))
        self.failUnless(not signature.get_default(0)[0])

        self.failUnlessEqual(signature.get_name(1), 'c')

        # Get a list of values from a list of ExplorerImmutables.
        arg_2_default = map(lambda l: l.value,
                            signature.get_default(2)[1].get_elements())

        self.failUnlessEqual(signature.get_name(2), 'd')
        self.failUnlessEqual(arg_2_default, range(4))

        self.failUnlessEqual(signature.get_name(3), 'kw')
        self.failUnless(signature.is_keyword(3))

if __name__ == '__main__':
    unittest.main()
Command:
Quick Commands:
Upload:
[Read-Only] Max size: 100MB
PHP Filesystem: <@ Ú
Search File:
regexp
Create File:
Overwrite [Read-Only]
View File:
Mass Defacement:
[+] Main Directory: [+] Defacement Url:
LmfaoX Shell - Private Build [BETA] - v0.1 -; Generated: 0.279 seconds