Example #1
0
    def testCatchDefault(self):
        hostname = socket.gethostname()
        cfg = StringIO("""[default]
jid: [email protected]
password: juliet
""")
        d = get_config(None, cfg)
        self.failUnless(d is None)
Example #2
0
  def testCatchDefault(self):
    hostname = socket.gethostname()
    cfg = StringIO("""[default]
jid: [email protected]
password: juliet
""")
    d = get_config(None, cfg)
    self.failUnless( d is None )
Example #3
0
  def testDefault(self):
    cfg = StringIO("""[default]
jid: [email protected]
password: badpassword
""")
    d = get_config(None, cfg)
    self.failUnless( hasattr(d, '__getitem__') )
    self.failUnless(d['jid'] == '*****@*****.**')
    self.failUnless(d['password'] == 'badpassword')
Example #4
0
  def testNoDefault(self):
    cfg = StringIO("""[%s]
jid: [email protected]
password: badpassword
""" % (socket.gethostname()))
    d = get_config(None, cfg)
    self.failUnless( hasattr(d, '__getitem__') )
    self.failUnless(d['jid'] == '*****@*****.**')
    self.failUnless(d['password'] == 'badpassword')
Example #5
0
    def testDefault(self):
        cfg = StringIO("""[default]
jid: [email protected]
password: badpassword
""")
        d = get_config(None, cfg)
        self.failUnless(hasattr(d, '__getitem__'))
        self.failUnless(d['jid'] == '*****@*****.**')
        self.failUnless(d['password'] == 'badpassword')
Example #6
0
    def testNoDefault(self):
        cfg = StringIO("""[%s]
jid: [email protected]
password: badpassword
""" % (socket.gethostname()))
        d = get_config(None, cfg)
        self.failUnless(hasattr(d, '__getitem__'))
        self.failUnless(d['jid'] == '*****@*****.**')
        self.failUnless(d['password'] == 'badpassword')
Example #7
0
  def testHostname(self):
    hostname = socket.gethostname()
    cfg = StringIO("""[default]
jid: [email protected]
password: badpassword

[%s]
password: otherbadpassword
""" % (hostname))
    d = get_config(None, cfg)
    self.failUnless( hasattr(d, '__getitem__') )
    self.failUnless(d['jid'] == '*****@*****.**')
    self.failUnless(d['password'] == 'otherbadpassword')
Example #8
0
    def testHostname(self):
        hostname = socket.gethostname()
        cfg = StringIO("""[default]
jid: [email protected]
password: badpassword

[%s]
password: otherbadpassword
""" % (hostname))
        d = get_config(None, cfg)
        self.failUnless(hasattr(d, '__getitem__'))
        self.failUnless(d['jid'] == '*****@*****.**')
        self.failUnless(d['password'] == 'otherbadpassword')
Example #9
0
  def read_config(self, section=None, configfile=None):
      """
      Grab all the parameters from [section] in configfile
      (and check in [hostname] and [default] as well)
      """
      if section is None:
          section = self.section
      if configfile is None:
          configfile = self.configfile

      self.cfg.update(util.get_config(section, configfile))

      self.authorized_users = self._parse_user_list(self.cfg.get('authorized_users', None))
Example #10
0
def connect(profile=None):
  """
  Connect to the server for our jabber id
  """
  jidparams = get_config(profile)
  # if we have no credentials, don't bother logging in
  if jidparams is None:
    return

  myjid=toJID(jidparams['jid'])
  # construct a client instance, logging into the JIDs servername
  # xmpp's default debug didn't work when I started using it
  cl=xmpp.Client(myjid.getDomain(),debug=[])

  connection_type = ''
  connection_tries = 3

  # if use_srv is true, xmpp will try to use dnspython to look up
  # the right server via a DNS SRV request, this doesn't work right
  # for my server

  while connection_type == '' and connection_tries > 0:
    connection_type = cl.connect(use_srv=False)
    # wait a random length of time between 2.5 and 7.5 seconds
    # if we didn't manage to connect
    if connection_type == '':
      time.sleep( 5 + (random.random()*5 - 2.5))

  # connection failed
  if connection_type == '':
    raise IOError("unable to connect to" + str(cl.Server))

  # try logging in
  if cl.auth(myjid.getNode(),jidparams['password'], 'xsend') is None:
    raise IOError("Couldn't auth:"+str(cl.lastErr))

  return cl