Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint fixes #527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import requests_html

project = 'requests-HTML'
copyright = u'MMXVIII. A <a href="http://kennethreitz.com/pages/open-projects.html">Kenneth Reitz</a> Project'
copyright = 'MMXVIII. A <a href="http://kennethreitz.com/pages/open-projects.html">Kenneth Reitz</a> Project'
author = 'Kenneth Reitz'

# The short X.Y version
Expand Down Expand Up @@ -208,4 +208,4 @@
# -- Options for todo extension ----------------------------------------------

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
todo_include_todos = True
34 changes: 17 additions & 17 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from functools import partial
from typing import Set, Union, List, MutableMapping, Optional

import http.cookiejar
import pyppeteer
import requests
import http.cookiejar

from pyquery import PyQuery

from fake_useragent import UserAgent
Expand Down Expand Up @@ -94,8 +95,7 @@ def raw_html(self) -> _RawHTML:
"""
if self._html:
return self._html
else:
return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)
return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)

@property
def html(self) -> _BaseHTML:
Expand All @@ -104,8 +104,7 @@ def html(self) -> _BaseHTML:
"""
if self._html:
return self.raw_html.decode(self.encoding, errors='replace')
else:
return etree.tostring(self.element, encoding='unicode').strip()
return etree.tostring(self.element, encoding='unicode').strip()

@html.setter
def html(self, html: str) -> None:
Expand Down Expand Up @@ -377,7 +376,7 @@ class Element(BaseParser):
]

def __init__(self, *, element, url: _URL, default_encoding: _DefaultEncoding = None) -> None:
super(Element, self).__init__(element=element, url=url, default_encoding=default_encoding)
super().__init__(element=element, url=url, default_encoding=default_encoding)
self.element = element
self.tag = element.tag
self.lineno = element.sourceline
Expand Down Expand Up @@ -418,7 +417,7 @@ def __init__(self, *, session: Union['HTMLSession', 'AsyncHTMLSession'] = None,
html = html.encode(DEFAULT_ENCODING)

pq = PyQuery(html)
super(HTML, self).__init__(
super().__init__(
element=pq('html') or pq.wrapAll('<html></html>')('html'),
html=html,
url=url,
Expand Down Expand Up @@ -469,8 +468,7 @@ def get_next():

if fetch:
return self.session.get(url)
else:
return url
return url

def __iter__(self):

Expand Down Expand Up @@ -566,9 +564,11 @@ def _convert_cookiejar_to_render(self, session_cookiejar):
def __convert(cookiejar, key):
try:
v = eval ("cookiejar."+key)
if not v: kv = ''
else: kv = {key: v}
except:
if not v:
kv = ''
else:
kv = {key: v}
except Exception:
kv = ''
return kv

Expand Down Expand Up @@ -654,9 +654,9 @@ def render(self, retries: int = 8, script: str = None, wait: float = 0.2, scroll
reload = False

if send_cookies_session:
cookies = self._convert_cookiesjar_to_render()
cookies = self._convert_cookiesjar_to_render()

for i in range(retries):
for _ in range(retries):
if not content:
try:

Expand Down Expand Up @@ -685,7 +685,7 @@ async def arender(self, retries: int = 8, script: str = None, wait: float = 0.2,
reload = False

if send_cookies_session:
cookies = self._convert_cookiesjar_to_render()
cookies = self._convert_cookiesjar_to_render()

for _ in range(retries):
if not content:
Expand All @@ -712,7 +712,7 @@ class HTMLResponse(requests.Response):
"""

def __init__(self, session: Union['HTMLSession', 'AsyncHTMLSession']) -> None:
super(HTMLResponse, self).__init__()
super().__init__()
self._html = None # type: HTML
self.session = session

Expand Down Expand Up @@ -787,7 +787,7 @@ async def browser(self):
class HTMLSession(BaseSession):

def __init__(self, **kwargs):
super(HTMLSession, self).__init__(**kwargs)
super().__init__(**kwargs)

@property
def browser(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import pytest
from pyppeteer.browser import Browser
from pyppeteer.page import Page
from requests_html import HTMLSession, AsyncHTMLSession, HTML
from requests_file import FileAdapter
from requests_html import HTMLSession, AsyncHTMLSession, HTML


session = HTMLSession()
session.mount('file://', FileAdapter())
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_browser_session():
since no doing that will left the browser running. """
session = HTMLSession()
assert isinstance(session.browser, Browser)
assert hasattr(session, "loop") == True
assert hasattr(session, "loop") is True
session.close()
# assert count_chromium_process() == 0

Expand All @@ -313,7 +313,7 @@ def test_browser_process():
r = get()
r.html.render()

assert r.html.page == None
assert r.html.page is None


@pytest.mark.asyncio
Expand Down