3 # Released under the terms of the GPLv3
10 from subprocess
import Popen
, PIPE
12 from .constants
import USER_AGENT
13 from .readme
import README
15 def lynxDump(url
, lynxArgs
=[]):
16 if url
== "special:README":
20 p
= Popen(['lynx', '-dump', '-force_html', '-assume-charset=utf8', '-display-charset=utf8', '-useragent="%s via lynx"' % USER_AGENT
] +
22 stdin
=None, stdout
=PIPE
, stderr
=PIPE
, universal_newlines
=True)
23 (lynxStdout
, lynxErrout
) = (p
.stdout
, p
.stderr
)
25 return "", [], "Fatal error - lynx execution failed. Is it installed?"
31 for line
in lynxStdout
:
32 if line
== 'References\n':
34 # The previous matched 'References' was part of the
42 m
= re
.match(r
'\s*\d+\. (.*)\n', line
)
44 linkUrls
+= [m
.groups()[0]]
50 lynxErr
= lynxErrout
.read()
52 return dumped
, linkUrls
, lynxErr