Commit 4c76bc61 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

replace popen2.popen3 with subprocess.Popen.

parent 6905aa33
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
import unittest import unittest
import os import os
import popen2
import urllib import urllib
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
...@@ -443,12 +442,13 @@ class W3Validator(object): ...@@ -443,12 +442,13 @@ class W3Validator(object):
source = 'fragment=%s&output=soap12' % urllib.quote_plus(page_source) source = 'fragment=%s&output=soap12' % urllib.quote_plus(page_source)
os.environ['CONTENT_LENGTH'] = str(len(source)) os.environ['CONTENT_LENGTH'] = str(len(source))
os.environ['REQUEST_METHOD'] = 'POST' os.environ['REQUEST_METHOD'] = 'POST'
stdout, stdin, stderr = popen2.popen3(self.validator_path) process = Popen([self.validator_path],
stdin.write(source) stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
stdin.close() try:
while stdout.readline() != '\n': stdout, stderr = process.communicate(source)
pass finally:
result = stdout.read() del process
result = stdout.split('\n\n', 1)[-1]
return self._parse_validation_results(result) return self._parse_validation_results(result)
...@@ -489,9 +489,15 @@ class TidyValidator(object): ...@@ -489,9 +489,15 @@ class TidyValidator(object):
''' '''
retrun two list : a list of errors and an other for warnings retrun two list : a list of errors and an other for warnings
''' '''
stdout, stdin, stderr = popen2.popen3('%s -e -q -utf8' % self.validator_path) if isinstance(page_source, unicode):
stdin.write(page_source) # Zope 2.12 renders page templates as unicode
stdin.close() page_source = page_source.encode('utf-8')
process = Popen([self.validator_path, '-e', '-q', '-utf8'],
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
try:
stdout, stderr = process.communicate(page_source)
finally:
del process
return self._parse_validation_results(stderr) return self._parse_validation_results(stderr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment