Function that delivers cheat sheet for `query`. If `html` is True, the answer is formatted as HTML. Additional request options specified in `request_options`.
(query, request_options=None, output_format="ansi")
| 34 | |
| 35 | |
| 36 | def cheat_wrapper(query, request_options=None, output_format="ansi"): |
| 37 | """ |
| 38 | Function that delivers cheat sheet for `query`. |
| 39 | If `html` is True, the answer is formatted as HTML. |
| 40 | Additional request options specified in `request_options`. |
| 41 | """ |
| 42 | |
| 43 | def _rewrite_aliases(word): |
| 44 | if word == ":bash.completion": |
| 45 | return ":bash_completion" |
| 46 | return word |
| 47 | |
| 48 | def _rewrite_section_name(query): |
| 49 | """ |
| 50 | Rewriting special section names: |
| 51 | * EDITOR:NAME => emacs:go-mode |
| 52 | """ |
| 53 | |
| 54 | if "/" not in query: |
| 55 | return query |
| 56 | |
| 57 | section_name, rest = query.split("/", 1) |
| 58 | |
| 59 | if ":" in section_name: |
| 60 | section_name = rewrite_editor_section_name(section_name) |
| 61 | section_name = LANGUAGE_ALIAS.get(section_name, section_name) |
| 62 | |
| 63 | return "%s/%s" % (section_name, rest) |
| 64 | |
| 65 | def _sanitize_query(query): |
| 66 | return re.sub('[<>"]', "", query) |
| 67 | |
| 68 | def _strip_hyperlink(query): |
| 69 | return re.sub("(,[0-9]+)+$", "", query) |
| 70 | |
| 71 | def _parse_query(query): |
| 72 | topic = query |
| 73 | keyword = None |
| 74 | search_options = "" |
| 75 | |
| 76 | keyword = None |
| 77 | if "~" in query: |
| 78 | topic = query |
| 79 | pos = topic.index("~") |
| 80 | keyword = topic[pos + 1 :] |
| 81 | topic = topic[:pos] |
| 82 | |
| 83 | if "/" in keyword: |
| 84 | search_options = keyword[::-1] |
| 85 | search_options = search_options[: search_options.index("/")] |
| 86 | keyword = keyword[: -len(search_options) - 1] |
| 87 | |
| 88 | return topic, keyword, search_options |
| 89 | |
| 90 | query = _sanitize_query(query) |
| 91 | query = _add_section_name(query) |
| 92 | query = _rewrite_aliases(query) |
| 93 | query = _rewrite_section_name(query) |
no test coverage detected