Exemplo n.º 1
0
 def dorequest(self, method, path, postdata={}, headers={}):
     if postdata: postdata = urllib.urlencode(postdata)
     if headers:
         if not headers.has_key('Content-Length'): headers['Content-Length'] = len(postdata)
         headerstxt = ""
         for i,j in headers.iteritems(): headerstxt += "%s: %s\r\n" % (i.lower(), j)
     else: headerstxt = ""
     if method == 'POST': s = toenc("%s %s HTTP/1.0\r\n%s\r\n%s\r\n\r\n" % (method, path, headerstxt, postdata), 'ascii')
     else: s = toenc("%s %s HTTP/1.0\r\n\r\n" % (method, path), 'ascii')
     if self.start():
         logging.info('rest.client - %s - sending %s' % (self.url, s))
         self.push(s)
Exemplo n.º 2
0
 def _raw(self, stanza):
     """ output a xml stanza to the socket. """
     if self.stopped or self.failure: logging.info("%s - bot is stopped .. not sending" % self.cfg.name) ; return
     try:
         stanza = stanza.strip()
         if not stanza:
             logging.debug("%s - no stanze provided. called from: %s" % (self.cfg.name, whichmodule()))
             return
         what = jabberstrip(stanza, allowed=["\n", ])
         what = toenc(what)
         if not what.endswith('>') or not what.startswith('<'):
             logging.error('%s - invalid stanza: %s' % (self.cfg.name, what))
             return
         start = what[:3]
         if start in ['<st', '<me', '<pr', '<iq', "<au", "<re", "<fa", "<ab"]:
             if start == "<pr": logging.info(u"> %s" % what)
             else: logging.info(u"> %s" % what)
             if not self.connection: self.sock.send(what)
             else:
                 try: self.connection.send(what + u"\r\n")
                 except AttributeError:
                     try: self.connection.write(what)
                     except AttributeError: self.sock.send(what)
         else: logging.error('%s - invalid stanza: %s' % (self.cfg.name, what))
         if self.cfg.sleeptime: time.sleep(self.cfg.sleeptime)
         else: time.sleep(0.01)
     except socket.error, ex:
         if 'Broken pipe' in str(ex):
             logging.debug('%s - core - broken pipe .. ignoring' % self.cfg.name)
             return
         self.error = str(ex)
         handle_exception()
Exemplo n.º 3
0
 def _raw(self, stanza):
     """ output a xml stanza to the socket. """
     if not self.connection: return
     time.sleep(0.01)
     try:
         stanza = stanza.strip()
         if not stanza:
             logging.debug("%s - no stanze provided. called from: %s" % (self.name, whichmodule()))
             return
         what = jabberstrip(stanza)
         what = toenc(stanza)
         logging.debug("%s - out - %s" % (self.name, what))             
         if not what.endswith('>') or not what.startswith('<'):
             logging.error('%s - invalid stanza: %s' % (self.name, what))
             return
         if what.startswith('<stream') or what.startswith('<message') or what.startswith('<presence') or what.startswith('<iq'):
             logging.debug(u"%s - sxmpp - out - %s" % (self.name, what))
             try: self.connection.send(what + u"\r\n")
             except AttributeError: self.connection.write(what)
         else: logging.error('%s - invalid stanza: %s' % (self.name, what))
     except socket.error, ex:
         if 'Broken pipe' in str(ex):
             logging.debug('%s - core - broken pipe .. ignoring' % self.name)
             return
         self.error = str(ex)
         handle_exception()
Exemplo n.º 4
0
 def _raw(self, stanza):
     """ output a xml stanza to the socket. """
     if not self.connection: return
     time.sleep(0.01)
     try:
         stanza = stanza.strip()
         if not stanza:
             logging.debug("%s - no stanze provided. called from: %s" %
                           (self.name, whichmodule()))
             return
         what = jabberstrip(stanza)
         what = toenc(stanza)
         logging.debug("%s - out - %s" % (self.name, what))
         if not what.endswith('>') or not what.startswith('<'):
             logging.error('%s - invalid stanza: %s' % (self.name, what))
             return
         if what.startswith('<stream') or what.startswith(
                 '<message') or what.startswith(
                     '<presence') or what.startswith('<iq'):
             logging.debug(u"%s - sxmpp - out - %s" % (self.name, what))
             try:
                 self.connection.send(what + u"\r\n")
             except AttributeError:
                 self.connection.write(what)
         else:
             logging.error('%s - invalid stanza: %s' % (self.name, what))
     except socket.error, ex:
         if 'Broken pipe' in str(ex):
             logging.debug('%s - core - broken pipe .. ignoring' %
                           self.name)
             return
         self.error = str(ex)
         handle_exception()
Exemplo n.º 5
0
 def dorequest(self, method, path, postdata={}, headers={}):
     if postdata: postdata = urllib.urlencode(postdata)
     if headers:
         if not headers.has_key('Content-Length'):
             headers['Content-Length'] = len(postdata)
         headerstxt = ""
         for i, j in headers.iteritems():
             headerstxt += "%s: %s\r\n" % (i.lower(), j)
     else:
         headerstxt = ""
     if method == 'POST':
         s = toenc(
             "%s %s HTTP/1.0\r\n%s\r\n%s\r\n\r\n" %
             (method, path, headerstxt, postdata), 'ascii')
     else:
         s = toenc("%s %s HTTP/1.0\r\n\r\n" % (method, path), 'ascii')
     if self.start():
         logging.info('rest.client - %s - sending %s' % (self.url, s))
         self.push(s)
Exemplo n.º 6
0
Arquivo: irc.py Projeto: code2u/jsb
 def _raw(self, txt):
     """ send raw text to the server. """
     if not txt or self.stopped or not self.sock:
         logging.info("%s - bot is stopped .. not sending." % self.cfg.name)
         return 0
     try:
         self.lastoutput = time.time()
         itxt = toenc(txt, self.encoding)
         if not self.sock: logging.warn("%s - socket disappeared - not sending." % self.cfg.name) ; return
         if not txt.startswith("PONG"): logging.info(u"%s - out:  %s" % (self.cfg.name, itxt))             
         if self.cfg.has_key('ssl') and self.cfg['ssl']: self.sock.write(itxt + '\n')
         else: self.sock.send(itxt[:500] + '\n')
     except Exception, ex: logging.error("%s - can't send: %s" % (self.cfg.name, str(ex)))
Exemplo n.º 7
0
 def _raw(self, txt):
     """ send raw text to the server. """
     if not txt or self.stopped or not self.sock:
         logging.info("%s - bot is stopped .. not sending." % self.name)
         return 0
     if not txt.startswith("PONG"):
         logging.info("%s - sending %s" % (self.name, txt))
     try:
         self.lastoutput = time.time()
         itxt = toenc(txt, self.encoding)
         logging.info(u"%s - out - %s" % (self.name, itxt))
         if not self.sock:
             logging.warn("%s - socket disappeared - not sending." %
                          self.name)
             return
         if self.cfg.has_key('ssl') and self.cfg['ssl']:
             self.sock.write(itxt + '\n')
         else:
             self.sock.send(itxt[:500] + '\n')
     except UnicodeEncodeError, ex:
         logging.error("%s - encoding error: %s" % (self.name, str(ex)))
         return
Exemplo n.º 8
0
 def _raw(self, txt):
     """ send raw text to the server. """
     if not txt or self.stopped or not self.sock:
         logging.debug("%s - bot is stopped .. not sending." %
                       self.cfg.name)
         return 0
     try:
         self.lastoutput = time.time()
         itxt = toenc(txt, self.encoding)
         if not self.sock:
             logging.debug("%s - socket disappeared - not sending." %
                           self.cfg.name)
             return
         if not txt.startswith("PONG"):
             logging.warn("> %s (%s)" % (itxt, self.cfg.name))
         else:
             logging.info("> %s (%s)" % (itxt, self.cfg.name))
         if self.cfg.has_key('ssl') and self.cfg['ssl']:
             self.sock.write(itxt + '\n')
         else:
             self.sock.send(itxt[:500] + '\n')
     except Exception, ex:
         logging.error("%s - can't send: %s" % (self.cfg.name, str(ex)))
Exemplo n.º 9
0
def getrssid(url, time):
    """ get an id based on url and time. """
    key = unicode(url) + unicode(time)
    return str(uuid.uuid3(uuid.NAMESPACE_DNS, toenc(key)))
Exemplo n.º 10
0
def getrssid(url, time):
    """ get an id based on url and time. """
    key = unicode(url) + unicode(time)
    return str(uuid.uuid3(uuid.NAMESPACE_DNS, toenc(key)))