Exemplo n.º 1
0
 def __init__(self, config):
     Runnable.__init__(self)
     self.db = Database()
     self.config = config
     self.load_configs()
     self.api = API(callback_add=self.callback_add_info_site)
     self.driver = WebDriver.build(config)
Exemplo n.º 2
0
    def __init__(self, host=None, port=0, sock=None):
        """
    Constructor.

    When called without arguments, create an unconnected instance.
    With a hostname argument, it connects the instance; port number
    and timeout are optional.
    """
        if sock:
            asyncore.dispatcher.__init__(self, sock)
        else:
            asyncore.dispatcher.__init__(self)
        self.sock = sock
        self.debuglevel = DEBUGLEVEL
        self.host = host
        self.port = port
        self.rawq = ''
        self.api = API()
        self.cookedq = ''
        self.eof = 0
        self.sbdataq = ''
        self._sbdatabuffer = ''
        self.outbuffer = ''
        self.options = {}
        self.option_callback = self.handleopt
        self.option_handlers = {}
        self.connected = False
        self.ttype = 'Unknown'
        self.debug_types = []
Exemplo n.º 3
0
    def __init__(self, sock, host, port):
        """
    init the class
    """
        Telnet.__init__(self, sock=sock)
        self.host = host
        self.port = port
        self.api = API()
        self.ttype = 'Client'
        self.connectedtime = None
        self.supports = {}
        self.pwtries = 0
        self.banned = False
        self.viewonly = False

        if sock:
            self.connected = True
            self.connectedtime = time.mktime(time.localtime())

        self.api('events.register')('to_client_event',
                                    self.addtooutbufferevent,
                                    prio=99)

        self.api('options.prepareclient')(self)

        self.state = PASSWORD
        self.addtooutbufferevent({
            'original':
            self.api('colors.convertcolors')(
                '@R#BP@w: @RPlease enter the proxy password:@w'),
            'dtype':
            'passwd'
        })
Exemplo n.º 4
0
    def __init__(self):
        """
    initialize the instance
    """
        self.plugins = {}
        self.pluginl = {}
        self.pluginm = {}
        self.pluginp = {}
        self.options = {}
        self.plugininfo = {}

        index = __file__.rfind(os.sep)
        if index == -1:
            self.basepath = "." + os.sep
        else:
            self.basepath = __file__[:index]

        self.api = API()
        self.savefile = os.path.join(self.api.BASEPATH, 'data', 'plugins',
                                     'loadedplugins.txt')
        self.loadedplugins = PersistentDict(self.savefile, 'c')
        self.sname = 'plugins'
        self.lname = 'Plugin Manager'

        self.api.add(self.sname, 'isinstalled', self.api_isinstalled)
        self.api.add(self.sname, 'getp', self.api_getp)
        self.api.add(self.sname, 'module', self.api_getmodule)
        self.api.add(self.sname, 'allplugininfo', self.api_allplugininfo)
        self.api.add(self.sname, 'savestate', self.savestate)
Exemplo n.º 5
0
    def __init__(self, name, sname, modpath, basepath, fullimploc):  # pylint: disable=too-many-arguments
        """
    initialize the instance
    The following things should not be done in __init__ in a plugin
      Interacting with anything in the api except api.add, api.overload
          or dependency.add
    """
        # Examples:
        #  name : 'Actions' - from plugin file variable NAME (long name)
        #  sname : 'actions' - from plugin file variable SNAME (short name)
        #  modpath : '/client/actions.py' - path relative to the plugins directory
        #  basepath : '/home/src/games/bastproxy/bp/plugins' - the full path to the
        #                                                         plugins directory
        #  fullimploc : 'plugins.client.actions' - import location

        self.author = ''
        self.purpose = ''
        self.version = 0
        self.priority = 100
        self.name = name
        self.sname = sname
        self.dependencies = []
        self.versionfuncs = {}
        self.reloaddependents = False
        self.summarytemplate = "%20s : %s"
        self.canreload = True
        self.canreset = True
        self.resetflag = True
        self.api = API()
        self.firstactiveprio = None
        self.loadedtime = time.time()
        self.savedir = os.path.join(self.api.BASEPATH, 'data', 'plugins',
                                    self.sname)
        try:
            os.makedirs(self.savedir)
        except OSError:
            pass
        self.savefile = os.path.join(self.api.BASEPATH, 'data', 'plugins',
                                     self.sname, 'settingvalues.txt')
        self.modpath = modpath
        self.basepath = basepath
        self.fullimploc = fullimploc
        self.pluginfile = os.path.join(basepath, modpath[1:])
        self.pluginlocation = os.path.normpath(
            os.path.join(self.api.BASEPATH, 'plugins') + \
              os.sep + os.path.dirname(self.modpath))

        self.package = fullimploc.split('.')[1]

        self.settings = {}
        self.settingvalues = PersistentDictEvent(self, self.savefile, 'c')

        self._dump_shallow_attrs = ['api']

        self.api.overload('dependency', 'add', self._api_dependencyadd)
        self.api.overload('setting', 'add', self._api_settingadd)
        self.api.overload('setting', 'gets', self._api_settinggets)
        self.api.overload('setting', 'change', self._api_settingchange)
        self.api.overload('api', 'add', self._api_add)
Exemplo n.º 6
0
 def __init__(self, telnetobj, option):
   """
   initalize the instance
   """
   self.api = API()
   self.telnetobj = telnetobj
   self.option = option
   self.telnetobj.option_handlers[ord(self.option)] = self
Exemplo n.º 7
0
 def __init__(self, telnetobj, option, plugin):
     """
 initalize the instance
 """
     tapi = API()
     self.telnetobj = telnetobj
     self.option = option
     self.telnetobj.option_handlers[ord(self.option)] = self
     self.plugin = tapi('plugins.getp')(plugin)
Exemplo n.º 8
0
    def api_sendpacket(self, message):
        """  send an A102 packet
    @Ymessage@w  = the message to send

    Format: IAC SB A102 <atcp message text> IAC SE

    this function returns no values"""
        from libs.api import API
        api = API()
        api.get('events.eraise')('to_mud_event', {'data':'%s%s%s%s%s%s' % \
              (IAC, SB, A102, message.replace(IAC, IAC+IAC), IAC, SE),
              'raw':True, 'dtype':A102})
Exemplo n.º 9
0
 def __init__(self):
     """
 initialize the class
 """
     self.currenttrace = None
     self.api = API()
     self.api('api.add')('send', 'msg', self._api_msg)
     self.api('api.add')('send', 'error', self._api_error)
     self.api('api.add')('send', 'traceback', self._api_traceback)
     self.api('api.add')('send', 'client', self._api_client)
     self.api('api.add')('send', 'mud', self._api_tomud)
     self.api('api.add')('send', 'execute', self._api_execute)
     self.api('managers.add')('io', self)
Exemplo n.º 10
0
    def __init__(self, name, sname, modpath, basepath, fullimploc):
        # pylint: disable=too-many-arguments
        """
    initialize the instance
    The following things should not be done in __init__ in a plugin
      Interacting with anything in the api except api.add, api.overload
          or dependency.add
    """
        self.author = ''
        self.purpose = ''
        self.version = 0
        self.priority = 100
        self.name = name
        self.sname = sname
        self.dependencies = []
        self.versionfuncs = {}
        self.reloaddependents = False
        self.canreload = True
        self.resetflag = True
        self.api = API()
        self.loadedtime = time.time()
        self.savedir = os.path.join(self.api.BASEPATH, 'data', 'plugins',
                                    self.sname)
        try:
            os.makedirs(self.savedir)
        except OSError:
            pass
        self.savefile = os.path.join(self.api.BASEPATH, 'data', 'plugins',
                                     self.sname, 'settingvalues.txt')
        self.modpath = modpath
        self.basepath = basepath
        self.fullimploc = fullimploc
        self.pluginfile = os.path.join(basepath, modpath[1:])
        self.pluginlocation = os.path.normpath(
            os.path.join(self.api.BASEPATH, 'plugins') + \
              os.sep + os.path.dirname(self.modpath))

        self.package = fullimploc.split('.')[1]

        self.settings = {}
        self.settingvalues = PersistentDictEvent(self, self.savefile, 'c')

        self._dump_shallow_attrs = ['api']

        self.api.overload('dependency', 'add', self.api_dependencyadd)
        self.api.overload('setting', 'add', self.api_settingadd)
        self.api.overload('setting', 'gets', self.api_settinggets)
        self.api.overload('setting', 'change', self.api_settingchange)
        self.api.overload('api', 'add', self.api_add)
Exemplo n.º 11
0
    def __init__(self):
        """
    init the class
    """
        Telnet.__init__(self)

        self.username = None
        self.password = None
        self.api = API()
        self.lastmsg = ''
        self.clients = []
        self.vclients = []
        self.ttype = 'BastProxy'
        self.banned = {}
        self.connectedtime = None
        self.api('events.register')('to_mud_event',
                                    self.addtooutbuffer,
                                    prio=99)
        self.api('options.prepareserver')(self)
Exemplo n.º 12
0
  def __init__(self, filename, flag='c', mode=None,
               tformat='json', *args, **kwds):
    """
    initialize the instance
    """
    self._dump_shallow_attrs = ['api']
    self.api = API()

    # r=readonly, c=create, or n=new
    self.flag = flag

    # None or an octal triple like 0644
    self.mode = (stat.S_IWUSR | stat.S_IRUSR) or mode

    # 'csv', 'json', or 'pickle'
    self.format = tformat
    self.filename = filename
    self.pload()
    dict.__init__(self, *args, **kwds)