From 03bae9e5da8adf2b5b5189638a172e5a13a3432f Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 19 May 2019 19:00:30 +0000 Subject: [PATCH] queries may contain spaces; first word is the section --- etc/config.yaml | 2 +- lib/adapter/question.py | 2 ++ lib/cheat_wrapper.py | 12 ++++++++++++ tests/results/9 | 21 +++++++++++++++------ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/etc/config.yaml b/etc/config.yaml index 058e54c..afdba64 100644 --- a/etc/config.yaml +++ b/etc/config.yaml @@ -1,4 +1,4 @@ server: address: "0.0.0.0" cache: - type: none + type: redis diff --git a/lib/adapter/question.py b/lib/adapter/question.py index c9dc670..7c56bf8 100644 --- a/lib/adapter/question.py +++ b/lib/adapter/question.py @@ -47,6 +47,8 @@ class Question(UpstreamAdapter): self._output_format = "ansi" return UpstreamAdapter._get_page(self, topic, request_options=request_options) + topic = topic.replace('+', ' ') + # if there is a language name in the section name, # cut it off (de:python => python) if '/' in topic: diff --git a/lib/cheat_wrapper.py b/lib/cheat_wrapper.py index 9f66efb..4e135bd 100644 --- a/lib/cheat_wrapper.py +++ b/lib/cheat_wrapper.py @@ -26,6 +26,17 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'): Additional request options specified in `request_options`. """ + def _add_section_name(query): + # temporary solution before we don't find a fixed one + if ' ' not in query and '+' not in query: + return query + if '/' in query: + return query + if ' ' in query: + # for standalone queries only that may contain ' ' + return "%s/%s" % tuple(query.split(' ', 1)) + return "%s/%s" % tuple(query.split('+', 1)) + def _rewrite_aliases(word): if word == ':bash.completion': return ':bash_completion' @@ -74,6 +85,7 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'): return topic, keyword, search_options query = _sanitize_query(query) + query = _add_section_name(query) query = _rewrite_aliases(query) query = _rewrite_section_name(query) diff --git a/tests/results/9 b/tests/results/9 index 33b4d5d..d5f9028 100644 --- a/tests/results/9 +++ b/tests/results/9 @@ -1,7 +1,16 @@ -Unknown topic. -Do you mean one of these topics maybe? +# How do I copy a file in Python? +#  +# shutil (http://docs.python.org/3/library/shutil.html) has many methods +# you can use. One of which is: - * python/:learn 69 - * python/Classes 67 - * python/Modules 67 - +from shutil import copyfile + +copyfile(src, dst) + +# Copy the contents of the file named src to a file named dst. The +# destination location must be writable; otherwise, an IOError exception +# will be raised. If dst already exists, it will be replaced. Special +# files such as character or block devices and pipes cannot be copied +# with this function. src and dst are path names given as strings. +#  +# [Swati] [so/q/123198] [cc by-sa 3.0]