def asyncParseResult(rules, word, _pass): # asyncSubstitute = coopReduce(func, rules, word) asyncSubstitute = asyncReduce(partial(maybeDeferred, func), rules, word) return asyncReturn(word) if _pass else asyncSubstitute
def asyncParseResult(rules, word, _pass): # return asyncReturn(word) if _pass else coopReduce(func, rules, word) asyncFunc = partial(maybeDeferred, func) return asyncReturn(word) if _pass else asyncReduce(asyncFunc, rules, word)
def get_element(url): try: tree = objectify.parse(urlopen(url)) root = tree.getroot() except XMLSyntaxError: element = loads(urlopen(url).read()) else: # print etree.tostring(element, pretty_print=True) element = utils.etree_to_dict(root) return element # Async functions asyncParseResult = lambda element, path, _: asyncReduce(func, path, element) @inlineCallbacks def asyncGetParsed(_INPUT, asyncFunc): _input = yield _INPUT finite = utils.finitize(_input) confs = yield asyncImap(asyncFunc, finite) splits = imap(parse_conf, confs) asyncGetElement = partial(maybeDeferred, get_element) asyncFuncs = get_async_dispatch_funcs('pass', asyncGetElement) results = yield asyncDispatch(splits, *asyncFuncs) returnValue(results) @inlineCallbacks