本文整理匯總了Python中parser.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python parser.parse方法的具體用法?Python parser.parse怎麽用?Python parser.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類parser
的用法示例。
在下文中一共展示了parser.parse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: command
# 需要導入模塊: import parser [as 別名]
# 或者: from parser import parse [as 別名]
def command(command_data, session, db, add_to_updates_queue=True):
"""
Main command parsing function
:param command_data:
:param session:
:param db:
:param add_to_updates_queue:
:return: response object
"""
global processed_commands
global error_num
global success_num
processed_commands+=1
# Call the parser
command_data.update({"db": db})
parse_data = parser.parse(command_data, session)
command_id = command_data['id']
parse_data.update({"command_id": command_data['id']})
log.info(":{0}:Finished parsing".format(command_id))
response = plugin_handler.subscriptions().process_event(parse_data, db)
log.info("Got response {0} with type {1}".format(response, type(response)))
if response["type"] == "success":
success_num+=1
else:
error_num+=1
log.debug("Got response {0} from plugin handler".format(response))
log.info("{0}:Setting update for command with response {1}".format(
command_id, response
))
session_id = session['id']
#Add the response to the update queue
global sessions
if add_to_updates_queue:
sessions[session_id]["updates"].put({"command_id": command_id, "response": response})
if session_id in commands.keys():
commands[session_id].append([command_data["command"], response["text"]])
else:
commands.update({session_id:
[[command_data["command"], response["text"]]]})
return response
示例2: __init__
# 需要導入模塊: import parser [as 別名]
# 或者: from parser import parse [as 別名]
def __init__(self, content=None, base_path=None, base_uri=None, strict=False):
if content is not None:
self.data = parse(content, strict)
else:
self.data = {}
self._base_uri = base_uri
if self._base_uri:
if not self._base_uri.endswith('/'):
self._base_uri += '/'
self._initialize_attributes()
self.base_path = base_path