Exemplo n.º 1
0
 def __session_raw_command__(self, param):
     'Display XML command source.'
     self.append_note(SEPARATOR)
     if param and param[0] == 'd':  # d dict
         self.append_note(_T('Interpreted command'), 'BOLD')
         edoc = eppdoc_client.Message(self)
         edoc.parse_xml(self._raw_cmd)
         self.__put_raw_into_note__(edoc.create_data())
     else:  # e epp
         self.append_note(_T('Command source'), 'BOLD')
         self.append_note(human_readable(self._raw_cmd), 'GREEN')
Exemplo n.º 2
0
 def __init__(self, cwd=None):
     self._cwd = cwd
     ManagerBase.__init__(self, cwd=self._cwd)
     self._epp_cmd = eppdoc_client.Message(self)
     self._epp_response = eppdoc_client.Message(self)
     self.defs[objURI] = self._epp_cmd.get_objURI()
     self.defs[extURI] = self._epp_cmd.get_extURI()
     self._available_commands = self._epp_cmd.get_client_commands()
     self._lorry = None
     # Type of the answer. Here manager remembers what command sent
     # and along to this value sorted returned variables.
     self._command_sent = ''  # the name of the last sent command
     self._raw_cmd = ''  # XML EPP command sent to the server
     self._raw_answer = ''  # XML EPP server answer
     self._dct_answer = {}  # API response
     #... readline variables ...............
     self.readline = None
     self.readline_prefix = None
     self.readline_words = []
     self._startup_hook = ''  # text what will be put in prompt
     #......................................
     self.reset_src()
Exemplo n.º 3
0
 def __put_raw_into_note__(self, data):
     "Use pprint for displaying structured data (dict, XML-EPP)."
     if data is None:
         self.append_note(_T('No data'), ('RED', 'BOLD'))
     elif type(data) == dict:
         # Parsed data into dict
         self.append_note(eppdoc.prepare_display(data, COLOR))
     else:
         # XML EPP doc. only for better display
         edoc = eppdoc_client.Message(self)
         edoc.parse_xml(data)
         if edoc.is_error():
             self.append_note(
                 data,
                 'GREEN')  # Some errors occured during parsing process.
         else:
             self.append_note(edoc.get_xml(), 'GREEN')
Exemplo n.º 4
0
 def __session_fetch_from_info__(self, param):
     'Create command line from previous info'
     allowed = ('create', 'update', 'delete')
     params = re.split('\s+', param)
     # check if user sets param
     if not len(params):
         self.append_error('%s: %s.' %
                           (_T('Missing command type. Available types'),
                            ', '.join(allowed)))
         return
     display_as_note = 0
     command_type = params[0]
     if len(params) > 1: display_as_note = params[1][0] == 'n' and 1 or 0
     # check valid param
     if command_type not in allowed:
         self.append_error(
             '%s: %s.' %
             (_T('Invalid command type. Valid types'), ', '.join(allowed)))
         return
     # check if previous command was info
     match = re.match('^(\w+):info$', self._dct_answer['command'])
     if match is None:
         self.append_error(
             _T('At first you must receive values from info_[contact|nsset|domain].'
                ))
         return
     info_type = match.group(1)
     # check if info returned valid data
     if not len(self._dct_answer['data']):
         self.append_error(
             _T("Previous info_%s didn't return data.") %
             get_ltext(info_type))
         return
     # create command
     eppdoc = eppdoc_client.Message(self)
     cmd = eppdoc.fetch_from_info(command_type, info_type, self._dct_answer,
                                  self._session[NULL_VALUE])
     if self.readline and display_as_note == 0:
         self._startup_hook = cmd  # display directly on the prompt
     else:
         self.append_note(
             cmd
         )  # display as a note if tty doesn't support readline (Windows)
Exemplo n.º 5
0
 def grab_command_name_from_xml(self, message):
     "Save EPP command type for recognize server answer."
     # The Manager remember the type of the command and it is used
     # for method how to interpret received variables.
     # The type of the command must be grab directly from XML because
     # it is possible to send any XML from any unknown source or application.
     epp_xml = eppdoc_client.Message(self)
     epp_xml.parse_xml(message)
     err = epp_xml.fetch_errors()
     command_name = epp_xml.get_epp_command_name()
     if len(err):
         self._errors.append(err)
     else:
         match = re.match('(\w+):check', command_name)  # domain:check
         if match:
             names = epp_xml.get_check_names(match.group(1))
             if len(names):
                 # makte struct (key, verbose, description)
                 self._session[SORT_BY_COLUMNS] = map(
                     lambda s: (s, 1, s), names)
     return command_name