コード例 #1
0
def run_creation(options):
    global epp
    if epp is None:
        epp = ClientSession()
        epp.load_config()
        epp.set_auto_connect(0)  # set OFF auto connection
    command_name, epp_doc, stop = epp.create_eppdoc(options['command'])
    errors = epp.fetch_errors()
    if not epp_doc and not errors:
        errors = '%s %s' % (_T('Unknown command'),
                            command_name.encode(encoding))
    str_error = ''
    if errors:
        if type(command_name) == unicode:
            command_name = command_name.encode(encoding)
        if type(errors) == unicode: errors = errors.encode(encoding)
        if options['output'] == 'html':
            str_error = '<div class="fred_errors">\n<strong>%s errors:</strong>\n<pre>\n%s</pre><div>' % (
                command_name, escape_html(errors))
        elif options['output'] == 'php':
            str_error = '<?php\n$fred_error_create_name = %s;\n$fred_error_create_value = %s;\n%s\n?>' % (
                php_string(command_name), php_string(errors),
                epp.get_empty_php_code())
        elif options['output'] == 'xml':
            str_error = "<?xml version='1.0' encoding='%s'?>\n<errors>\n\t<error>%s</error>\n</errors>" % (
                encoding, errors)
        else:
            # default 'text'
            str_error = "%s: %s" % (_T('ERROR'), errors)
    return epp_doc, str_error
コード例 #2
0
ファイル: creator.py プロジェクト: mpvyard/fred-client
def run_creation(options):
    global epp
    command_name, errors, epp_doc = "", "", None
    if epp is None:
        epp = ClientSession()
        epp.load_config()
        if epp._conf.has_option("creator", "server_disclose_policy"):
            server_disclose_policy = epp._conf.get("creator",
                                                   "server_disclose_policy")
            if server_disclose_policy not in ("0", "1"):
                errors = "The variable 'server_disclose_policy' in config section [creator] has an unexpected value.\n"
            else:
                epp._epp_cmd.server_disclose_policy = int(
                    server_disclose_policy)
    if not errors:
        epp.set_auto_connect(0)  # set OFF auto connection
        command_name, epp_doc, stop = epp.create_eppdoc(options['command'])
        errors = epp.fetch_errors()
    if not epp_doc and not errors:
        errors = '%s %s' % (_T('Unknown command'),
                            command_name.encode(encoding))
    str_error = ''
    if errors:
        if type(command_name) == unicode:
            command_name = command_name.encode(encoding)
        if type(errors) == unicode: errors = errors.encode(encoding)
        if options['output'] == 'html':
            str_error = '<div class="fred_errors">\n<strong>%s errors:</strong>\n<pre>\n%s</pre><div>' % (
                command_name, escape_html(errors))
        elif options['output'] == 'php':
            str_error = '<?php\n$fred_error_create_name = %s;\n$fred_error_create_value = %s;\n%s\n?>' % (
                php_string(command_name), php_string(errors),
                epp.get_empty_php_code())
        elif options['output'] == 'xml':
            str_error = "<?xml version='1.0' encoding='%s'?>\n<errors>\n\t<error>%s</error>\n</errors>" % (
                encoding, errors)
        else:
            # default 'text'
            str_error = "%s: %s" % (_T('ERROR'), errors)
    return epp_doc, str_error
コード例 #3
0
ファイル: creator.py プロジェクト: kubicek/fred-client
def run_creation(options):
    global epp
    if epp is None:
        epp = ClientSession()
        epp.load_config()
        epp.set_auto_connect(0)  # set OFF auto connection
    command_name, epp_doc, stop = epp.create_eppdoc(options["command"])
    errors = epp.fetch_errors()
    if not epp_doc and not errors:
        errors = "%s %s" % (_T("Unknown command"), command_name.encode(encoding))
    str_error = ""
    if errors:
        if type(command_name) == unicode:
            command_name = command_name.encode(encoding)
        if type(errors) == unicode:
            errors = errors.encode(encoding)
        if options["output"] == "html":
            str_error = '<div class="fred_errors">\n<strong>%s errors:</strong>\n<pre>\n%s</pre><div>' % (
                command_name,
                escape_html(errors),
            )
        elif options["output"] == "php":
            str_error = "<?php\n$fred_error_create_name = %s;\n$fred_error_create_value = %s;\n%s\n?>" % (
                php_string(command_name),
                php_string(errors),
                epp.get_empty_php_code(),
            )
        elif options["output"] == "xml":
            str_error = "<?xml version='1.0' encoding='%s'?>\n<errors>\n\t<error>%s</error>\n</errors>" % (
                encoding,
                errors,
            )
        else:
            # default 'text'
            str_error = "%s: %s" % (_T("ERROR"), errors)
    return epp_doc, str_error
コード例 #4
0
def send_docs(display_bar, docs=[]):
    names = ()
    #-------------------------------------------------
    # Inicializace klienta
    #-------------------------------------------------
    epp = ClientSession()
    if not epp.load_config():
        return
    epp.join_missing_config_messages(options['verbose'])
    
    if len(options['verbose']):
        verbose = epp.set_verbose(options['verbose'])
    else:
        verbose = '1'

    #-------------------------------------------------
    # Apped docs from argv params
    #-------------------------------------------------
    for filepath in option_args:
        if os.path.isfile(filepath):
            docs.extend(split_docs(open(filepath).read()))
        else:
            docs.append((0,'File not found: %s'%filepath))
    #-------------------------------------------------
    # For every loaded document
    #-------------------------------------------------
    if display_bar:
        verbose = epp.set_verbose(0)
        sart_at = time.time()
        bar = None
        bar_pos = 0
        max = len(docs)
        bar_step = (100.0/max)*0.01
        bar_header = '%s: %d'%(_T('Send files'),max)
    epp.print_tag(BEGIN) # enclose leak messages into tag (comment)
    epp.display() # display errors or notes
    for code, xmldoc in docs:
        epp.reset_round()
        if code:
            # Returns command name from XML doc,
            # for check_* commands also grab list of names for sorting output
            command_name = epp.grab_command_name_from_xml(xmldoc)
            if len(command_name):
                if command_name in ('hello','login'):
                    epp.connect() # No problem call connect() if we are connected already.
                elif not epp.is_connected():
                    if not __auto_login__(epp, verbose): break
                if command_name == 'logout':
                    verbose = epp.set_verbose(0) # silent logout
                #-------------------------------------------------
                # when it is online send document
                #-------------------------------------------------
                if epp.is_online(command_name) and epp.is_connected():
                    # send document if only we are online
                    epp.send(xmldoc)          # send to server
                    xml_answer = epp.receive()     # receive answer
                    epp.process_answer(xml_answer) # process answer
                    epp.print_answer()
            epp.display() # display errors or notes
        else:
            if not display_bar:
                print epp.get_formated_message(xmldoc,1) # 0 - note, 1 - ERROR
        if display_bar:
            if bar is None: bar = terminal_controler.ProgressBar(colored_output,bar_header)
            bar.clear()
            bar.update(bar_pos, _T('sending...'))
            bar_pos += bar_step
    epp.print_tag(END) # end of enclosing leak messages
    if display_bar:
        # print final 100%
        note = "Ran test in %.3f sec"%(time.time() - sart_at)
        bar.clear()
        bar.update(1.0, note)

    #-------------------------------------------------
    # END of transmition - automatic logout
    #-------------------------------------------------
    if epp.is_connected():
        epp.set_verbose(0) # Very important! If is not set, it can overwrite outputed data.
        try:
            epp.api_command('logout') # automaticly logout
        except FredError, msg:
            pass # print 'ERROR:',msg