Esempio n. 1
0
def _verify_sort(sort_string):
    valid_field_names = ''
    field_names = to_str(sort_string).split(';')
    for name in field_names:
        if valid_provider_search_parameter(name):
            valid_field_names = valid_field_names + name + ';'
        else:
            log.warn("{0:s}: not a valid field_name")
    if valid_field_names:
        return valid_field_names.rstrip(';')
    return None
Esempio n. 2
0
 def install_opener(self, user=None, passwd=None):
     """Install (add) an opener which handles authentication and cookies."""
     if not (user and passwd):
         (user, passwd) = self.get_user_and_password()
     pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
     pm.add_password(None, get_auth_URL('login'), user, passwd)
     self.cookie_jar =  cookielib.LWPCookieJar()
     try:
         self.set_cookie_file(self.cookie_file)
     except OpenerError, e:
         e += "Unable to open cookie file"
         log.warn("{0:s}".format(str(e)))
Esempio n. 3
0
def install_opener(cookie_file, user=None, passwd=None):
    """Install (add) an opener which handles authentication and cookies."""
    if not (user and passwd):
        auth_file = path.join(path.expanduser('~'),'.auth/odesk/odesk_user')
        (user, passwd) = user_auth_from_file(auth_file)
    pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
    pm.add_password(None, get_auth_URL('login'), user, passwd)
    cookie_jar =  cookielib.LWPCookieJar()
    if cookie_file is None:
        cookie_file = 'cookies.txt'
    try:
        set_cookie_file(cookie_file)
    except OpenerError, e:
        e += "Unable to open cookie file"
        log.warn("{0:s}".format(str(e)))
Esempio n. 4
0
initLogger(logLevel=1, logConsole=True, logDisk=False)
stdout("should see debug message test 1\n")
log.debug("log test 1")
if test_fileobj('{0:s}'.format(pgm)) != 1:
    stdout('log file \"{0:s}\" should not have been created\n', pgm)
    errors += 1
else:
    stdout('Should see "Parameter not a file or file object."\n')
tests += 1
    
print

stdout("testing setLogLevel('warn'), should see only WARN: log test 2\n")
setLogLevel("warn")
log.debug("log test 2")
log.warn("log test 2")
print

stdout("shutting down logger, reinitializing with log level 0\n")
stdout("NullHander should prevent logger calls from generating warnings/errors.\n")
logging.shutdown()

initLogger(logLevel=0, logConsole=True, logDisk=False)
log.debug("this is an error.")
stdout('you should not see "this is an error." above\n')

stdout('after installing null handler, setting log level to debug\n')
setLogLevel('debug')
log.debug("this is not an error.")

logging.shutdown()
Esempio n. 5
0
        api.clean_exit(1)
    log.debug("app_main() returning {0!s}".format(argv2))
    return (api, argv2)

# This is intended only for testing.
if __name__ == '__main__':
    from odapi.logger import initLogger
    usage = """
  usage: $ {0:s} [OPTIONS]

  [OPTIONS]"""

    initLogger(logLevel='debug',logDisk=False, logConsole=True)

    (api, argv) = app_main(sys.argv[0], sys.argv, usage)

    api.pprint()

    stdout("api.log_level = {0:d}\n".format(api.log_level))
    setLogLevel("info", api)
    stdout('setLogLevel("info")\n')
    stdout("api.log_level = {0:d}\n".format(api.log_level))
    
    log.debug("log debug test")
    log.info("log info test")
    log.warn("log warn test")
    log.error("log error test")

    stderr("remaining in argv:\n\t {0!s}\n".format(argv))
    api.clean_exit(0)