def acquire(self, name):
     """ acquire lock """
     name = name.lower()
     if not self.locks.has_key(name):
         self.allocate(name)
     rlog(10, 'lockmanager', 'acquire %s' % name)
     self.locks[name].acquire()
Example #2
0
def geturl4(url, myheaders={}, postdata={}, keyfile="", certfile="", port=80):
    headers = {'Content-Type': 'text/html', \
'Accept': 'text/plain; text/html', 'User-Agent': useragent()}
    headers.update(myheaders)
    # parse URL components
    urlparts = urlparse.urlparse(url)
    try:
        port = int(urlparts[1].split(':')[1])
        host = urlparts[1].split(':')[0]
    except:
        host = urlparts[1]
    # set up HTTP connection
    if keyfile:
        connection = httplib.HTTPSConnection(host, port, keyfile, \
certfile)
    elif 'https' in urlparts[0]:
        connection = httplib.HTTPSConnection(host, port)
    else:
        connection = httplib.HTTPConnection(host, port)
    # make the request
    if type(postdata) == types.DictType:
        postdata = urllib.urlencode(postdata)
    rlog(10, 'url', 'fetching %s' % url)
    connection.request('GET', urlparts[2])
    # read the response and clean up
    return connection.getresponse()
Example #3
0
def cleanpycfile(filename):
    try:
        if filename.endswith('.pyc'):
            os.unlink(filename)
            rlog(10, 'generic', 'cleaned %s' % filename)
    except:
        pass
Example #4
0
def cleanpycfile(filename):
    try:
        if filename.endswith('.pyc'):
            os.unlink(filename)
            rlog(10, 'generic', 'cleaned %s' % filename)
    except:
        pass
Example #5
0
 def acquire(self, name):
     """ acquire lock """
     name = name.lower()
     if not self.locks.has_key(name):
         self.allocate(name)
     rlog(10, 'lockmanager', 'acquire %s' % name)
     self.locks[name].acquire()
Example #6
0
def geturl4(url, myheaders={}, postdata={}, keyfile="", certfile="", port=80):
    headers = {'Content-Type': 'text/html', \
'Accept': 'text/plain; text/html', 'User-Agent': useragent()}
    headers.update(myheaders)
    # parse URL components
    urlparts = urlparse.urlparse(url)
    try:
       port = int(urlparts[1].split(':')[1])
       host = urlparts[1].split(':')[0]
    except:
       host = urlparts[1]
    # set up HTTP connection
    if keyfile:
        connection = httplib.HTTPSConnection(host, port, keyfile, \
certfile)
    elif 'https' in urlparts[0]:
        connection = httplib.HTTPSConnection(host, port)
    else:
        connection = httplib.HTTPConnection(host, port)
    # make the request
    if type(postdata) == types.DictType:
        postdata = urllib.urlencode(postdata)
    rlog(10, 'url', 'fetching %s' % url)
    connection.request('GET', urlparts[2])
    # read the response and clean up
    return connection.getresponse()
Example #7
0
def deleteurl(url,
              myheaders={},
              postdata={},
              keyfile="",
              certfile="",
              port=80):
    """ very basic HTTP POST url retriever """
    # build headers
    headers = {'Content-Type': 'application/x-www-form-urlencoded', \
'Accept': 'text/plain; text/html', 'User-Agent': useragent()}
    headers.update(myheaders)
    # parse URL components
    urlparts = urlparse.urlparse(url)
    # set up HTTP connection
    if keyfile and certfile:
        connection = httplib.HTTPSConnection(urlparts[1], port, keyfile, \
certfile)
    else:
        connection = httplib.HTTPConnection(urlparts[1])
    # make the request
    if type(postdata) == types.DictType:
        postdata = urllib.urlencode(postdata)
    rlog(10, 'url', 'fetching %s' % url)
    connection.request('DELETE', urlparts[2], postdata, headers)
    # read the response and clean up
    return connection.getresponse()
Example #8
0
def geturl(url, version=None):
    """ fetch an url """
    urllib._urlopener = CBURLopener(version)
    rlog(10, 'url', 'fetching %s' % url)
    result = urllib.urlopen(url)
    tmp = result.read()
    result.close()
    return tmp
Example #9
0
def geturl(url, version=None):
    """ fetch an url """
    urllib._urlopener = CBURLopener(version)
    rlog(10, 'url', 'fetching %s' % url)
    result = urllib.urlopen(url)
    tmp = result.read()
    result.close()
    return tmp
Example #10
0
def getwho(bot, who):
    """ get userhost from bots userhost cache """
    who = who.lower()
    try:
        result = bot.userhosts[who]
        if bot.cfg['stripident']:
            rlog(10, 'getwho', 'removed ident from %s' % result)
            result = stripident(result)
        return result
    except KeyError:
        return None
Example #11
0
def getwho(bot, who):
    """ get userhost from bots userhost cache """
    who = who.lower()
    try:
        result = bot.userhosts[who]
        if bot.cfg['stripident']:
            rlog(10, 'getwho', 'removed ident from %s' % result)
            result = stripident(result)
        return result
    except KeyError:
        return None
Example #12
0
def geturl2(url, decode=False):
    """ use urllib2 to fetch an url """
    rlog(10, 'url', 'fetching %s' % url)
    request = urllib2.Request(url)
    request.add_header('User-Agent', useragent())
    opener = urllib2.build_opener()
    result = opener.open(request)
    tmp = result.read()
    info = result.info()  # add header information to .info attribute
    result.close()
    if decode:
        encoding = get_encoding(tmp)
        rlog(0, 'url', '%s encoding: %s' % (url, encoding))
        res = istr(fromenc(tmp, encoding, url))
    else:
        res = istr(tmp)
    res.info = info
    return res
Example #13
0
def geturl2(url, decode=False):
    """ use urllib2 to fetch an url """
    rlog(10, 'url', 'fetching %s' % url)
    request = urllib2.Request(url)
    request.add_header('User-Agent', useragent())
    opener = urllib2.build_opener()
    result = opener.open(request)
    tmp = result.read()
    info = result.info() # add header information to .info attribute
    result.close()
    if decode:
        encoding = get_encoding(tmp)
        rlog(0, 'url', '%s encoding: %s' % (url, encoding))
        res = istr(fromenc(tmp, encoding, url))
    else:
        res = istr(tmp)
    res.info = info
    return res
Example #14
0
def puturl(url, myheaders={}, postdata={}, keyfile="", certfile="", port=80):
    """ very basic HTTP POST url retriever """
    # build headers
    headers = {'Content-Type': 'application/x-www-form-urlencoded', \
'Accept': 'text/plain; text/html', 'User-Agent': useragent()}
    headers.update(myheaders)
    # parse URL components
    urlparts = urlparse.urlparse(url)
    # set up HTTP connection
    if keyfile:
        connection = httplib.HTTPSConnection(urlparts[1], port, keyfile, \
certfile)
    else:
        connection = httplib.HTTPConnection(urlparts[1])
    # make the request
    if type(postdata) == types.DictType:
        postdata = urllib.urlencode(postdata)
    rlog(10, 'url', 'fetching %s' % url)
    connection.request('PUT', urlparts[2], postdata, headers)
    # read the response and clean up
    return connection.getresponse()
Example #15
0
 def release(self, name):
     """ release lock """
     name = name.lower()
     rlog(10, 'lockmanager', 'releasing %s' % name)
     self.locks[name].release()
Example #16
0
 def allocate(self, name):
     """ allocate a new lock """
     name = name.lower()
     self.locks[name] = thread.allocate_lock()
     rlog(10, 'lockmanager', 'allocated %s' % name)
 def allocate(self, name):
     """ allocate a new lock """
     name = name.lower()
     self.locks[name] = thread.allocate_lock()
     rlog(10, 'lockmanager', 'allocated %s' % name)
 def release(self, name):
     """ release lock """
     name = name.lower()
     rlog(10, 'lockmanager', 'releasing %s' % name)
     self.locks[name].release()