mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 05:06:44 +02:00
Request raw upstream data
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
server:
|
||||
address: "0.0.0.0"
|
||||
cache:
|
||||
type: redis
|
||||
type: none
|
||||
|
||||
@@ -44,7 +44,7 @@ class Question(UpstreamAdapter):
|
||||
|
||||
if not os.path.exists(CONFIG["path.internal.bin.upstream"]):
|
||||
# if the upstream program is not found, use normal upstream adapter
|
||||
self._output_format = "ansi"
|
||||
# self._output_format = "ansi"
|
||||
return UpstreamAdapter._get_page(self, topic, request_options=request_options)
|
||||
|
||||
topic = topic.replace('+', ' ')
|
||||
|
||||
@@ -47,7 +47,7 @@ class UpstreamAdapter(Adapter):
|
||||
"""
|
||||
|
||||
_adapter_name = "upstream"
|
||||
_output_format = "ansi"
|
||||
_output_format = "text+code"
|
||||
_cache_needed = True
|
||||
|
||||
def _get_page(self, topic, request_options=None):
|
||||
@@ -55,7 +55,7 @@ class UpstreamAdapter(Adapter):
|
||||
options_string = "&".join(["%s=%s" % (x, y) for (x, y) in request_options.items()])
|
||||
url = CONFIG["upstream.url"].rstrip('/') \
|
||||
+ '/' + topic.lstrip('/') \
|
||||
+ "?" + options_string
|
||||
+ "?cT" # + options_string
|
||||
try:
|
||||
response = requests.get(url, timeout=CONFIG["upstream.timeout"])
|
||||
answer = response.text
|
||||
|
||||
+3
-3
@@ -261,7 +261,7 @@ def code_blocks(text, wrap_lines=False, unindent_code=False):
|
||||
Split `text` into blocks of text and code.
|
||||
Return list of tuples TYPE, TEXT
|
||||
"""
|
||||
text = text.encode('utf-8')
|
||||
# text = text.encode('utf-8')
|
||||
|
||||
lines = [x.rstrip('\n') for x in text.splitlines()]
|
||||
lines_classes = zip(_classify_lines(lines), lines)
|
||||
@@ -296,8 +296,8 @@ def beautify(text, lang, options):
|
||||
# if mode is unknown, just don't transform the text at all
|
||||
return text
|
||||
|
||||
text = text.encode('utf-8')
|
||||
digest = "t:%s:%s:%s" % (hashlib.md5(text).hexdigest(), lang, mode)
|
||||
# text = text.encode('utf-8')
|
||||
digest = "t:%s:%s:%s" % (hashlib.md5(text.encode("utf-8")).hexdigest(), lang, mode)
|
||||
|
||||
# temporary added line that removes invalid cache entries
|
||||
# that used wrong commenting methods
|
||||
|
||||
Reference in New Issue
Block a user