Fix flake8 issues after #14225

This commit is contained in:
Yen Chi Hsuan 2017-09-17 13:53:04 +08:00
parent 8251af63a1
commit 4ed2d7b7d1
2 changed files with 18 additions and 17 deletions

View File

@ -2452,7 +2452,7 @@ def _float(self, v, name, fatal=False, **kwargs):
def _set_cookie(self, domain, name, value, expire_time=None, port=None, def _set_cookie(self, domain, name, value, expire_time=None, port=None,
path='/', secure=False, discard=False, rest={}, **kwargs): path='/', secure=False, discard=False, rest={}, **kwargs):
cookie = compat_cookiejar.Cookie( cookie = compat_cookiejar.Cookie(
0, name, value, port, not port is None, domain, True, 0, name, value, port, port is not None, domain, True,
domain.startswith('.'), path, True, secure, expire_time, domain.startswith('.'), path, True, secure, expire_time,
discard, None, None, rest) discard, None, None, rest)
self._downloader.cookiejar.set_cookie(cookie) self._downloader.cookiejar.set_cookie(cookie)

View File

@ -3830,23 +3830,23 @@ def cookie_to_dict(cookie):
cookie_dict = { cookie_dict = {
'name': cookie.name, 'name': cookie.name,
'value': cookie.value, 'value': cookie.value,
}; }
if cookie.port_specified: if cookie.port_specified:
cookie_dict['port'] = cookie.port cookie_dict['port'] = cookie.port
if cookie.domain_specified: if cookie.domain_specified:
cookie_dict['domain'] = cookie.domain cookie_dict['domain'] = cookie.domain
if cookie.path_specified: if cookie.path_specified:
cookie_dict['path'] = cookie.path cookie_dict['path'] = cookie.path
if not cookie.expires is None: if cookie.expires is not None:
cookie_dict['expires'] = cookie.expires cookie_dict['expires'] = cookie.expires
if not cookie.secure is None: if cookie.secure is not None:
cookie_dict['secure'] = cookie.secure cookie_dict['secure'] = cookie.secure
if not cookie.discard is None: if cookie.discard is not None:
cookie_dict['discard'] = cookie.discard cookie_dict['discard'] = cookie.discard
try: try:
if (cookie.has_nonstandard_attr('httpOnly') or if (cookie.has_nonstandard_attr('httpOnly') or
cookie.has_nonstandard_attr('httponly') or cookie.has_nonstandard_attr('httponly') or
cookie.has_nonstandard_attr('HttpOnly')): cookie.has_nonstandard_attr('HttpOnly')):
cookie_dict['httponly'] = True cookie_dict['httponly'] = True
except TypeError: except TypeError:
pass pass
@ -3957,7 +3957,7 @@ def _load_cookies(self):
cookies = json.loads(f.read().decode('utf-8')) cookies = json.loads(f.read().decode('utf-8'))
for cookie in cookies: for cookie in cookies:
if cookie['httponly'] is True: if cookie['httponly'] is True:
cookie['rest'] = { 'httpOnly': None } cookie['rest'] = {'httpOnly': None}
if 'expiry' in cookie: if 'expiry' in cookie:
cookie['expire_time'] = cookie['expiry'] cookie['expire_time'] = cookie['expiry']
self.extractor._set_cookie(**cookie) self.extractor._set_cookie(**cookie)
@ -3965,7 +3965,7 @@ def _load_cookies(self):
def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on webpage', headers={}, jscode='saveAndExit();'): def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on webpage', headers={}, jscode='saveAndExit();'):
""" """
Downloads webpage (if needed) and executes JS Downloads webpage (if needed) and executes JS
Params: Params:
url: website url url: website url
html: optional, html code of website html: optional, html code of website
@ -3974,11 +3974,11 @@ def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on w
note2: optional, displayed when executing JS note2: optional, displayed when executing JS
headers: custom http headers headers: custom http headers
jscode: code to be executed when page is loaded jscode: code to be executed when page is loaded
Returns tuple with: Returns tuple with:
* downloaded website (after JS execution) * downloaded website (after JS execution)
* anything you print with `console.log` (but not inside `page.execute`!) * anything you print with `console.log` (but not inside `page.execute`!)
In most cases you don't need to add any `jscode`. In most cases you don't need to add any `jscode`.
It is executed in `page.onLoadFinished`. It is executed in `page.onLoadFinished`.
`saveAndExit();` is mandatory, use it instead of `phantom.exit()` `saveAndExit();` is mandatory, use it instead of `phantom.exit()`
@ -3992,7 +3992,7 @@ def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on w
else else
window.setTimeout(check, 500); window.setTimeout(check, 500);
} }
page.evaluate(function(){ page.evaluate(function(){
document.querySelector('#a').click(); document.querySelector('#a').click();
}); });
@ -4024,13 +4024,14 @@ def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on w
else: else:
self.extractor.to_screen('%s: %s' % (video_id, note2)) self.extractor.to_screen('%s: %s' % (video_id, note2))
p = subprocess.Popen([self.exe, '--ssl-protocol=any', p = subprocess.Popen([
self._TMP_FILES['script'].name], stdout=subprocess.PIPE, self.exe, '--ssl-protocol=any',
stderr=subprocess.PIPE) self._TMP_FILES['script'].name
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
if p.returncode != 0: if p.returncode != 0:
raise ExtractorError('Executing JS failed\n:' raise ExtractorError(
+ encodeArgument(err)) 'Executing JS failed\n:' + encodeArgument(err))
with open(self._TMP_FILES['html'].name, 'rb') as f: with open(self._TMP_FILES['html'].name, 'rb') as f:
html = f.read().decode('utf-8') html = f.read().decode('utf-8')