Skip to content

Commit 03bae9e

Browse files
committed
queries may contain spaces; first word is the section
1 parent 63a716f commit 03bae9e

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

etc/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
server:
22
address: "0.0.0.0"
33
cache:
4-
type: none
4+
type: redis

lib/adapter/question.py

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def _get_page(self, topic, request_options=None):
4747
self._output_format = "ansi"
4848
return UpstreamAdapter._get_page(self, topic, request_options=request_options)
4949

50+
topic = topic.replace('+', ' ')
51+
5052
# if there is a language name in the section name,
5153
# cut it off (de:python => python)
5254
if '/' in topic:

lib/cheat_wrapper.py

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
2626
Additional request options specified in `request_options`.
2727
"""
2828

29+
def _add_section_name(query):
30+
# temporary solution before we don't find a fixed one
31+
if ' ' not in query and '+' not in query:
32+
return query
33+
if '/' in query:
34+
return query
35+
if ' ' in query:
36+
# for standalone queries only that may contain ' '
37+
return "%s/%s" % tuple(query.split(' ', 1))
38+
return "%s/%s" % tuple(query.split('+', 1))
39+
2940
def _rewrite_aliases(word):
3041
if word == ':bash.completion':
3142
return ':bash_completion'
@@ -74,6 +85,7 @@ def _parse_query(query):
7485
return topic, keyword, search_options
7586

7687
query = _sanitize_query(query)
88+
query = _add_section_name(query)
7789
query = _rewrite_aliases(query)
7890
query = _rewrite_section_name(query)
7991

tests/results/9

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
Unknown topic.
2-
Do you mean one of these topics maybe?
1+
# How do I copy a file in Python?
2+
# 
3+
# shutil (http://docs.python.org/3/library/shutil.html) has many methods
4+
# you can use. One of which is:
35

4-
* python/:learn 69
5-
* python/Classes 67
6-
* python/Modules 67
7-
6+
from shutil import copyfile
7+
8+
copyfile(src, dst)
9+
10+
# Copy the contents of the file named src to a file named dst. The
11+
# destination location must be writable; otherwise, an IOError exception
12+
# will be raised. If dst already exists, it will be replaced. Special
13+
# files such as character or block devices and pipes cannot be copied
14+
# with this function. src and dst are path names given as strings.
15+
# 
16+
# [Swati] [so/q/123198] [cc by-sa 3.0]

0 commit comments

Comments
 (0)