Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
woob
woob
Compare revisions
a1292378075d6731e4adcb66083a31e4ea43844b to 695976f8c38a1af87b5231e21224f8b77473451a
Commits on Source (3)
filters: Add number/range type to FormValue, and tests
· 4b955145
Lowik BOURGEOISAT
authored
Jul 18, 2019
and
hydrargyrum
committed
Sep 11, 2019
4b955145
filters: Add color to FormValue
· fb3ebfbb
Lowik BOURGEOISAT
authored
Jul 19, 2019
and
hydrargyrum
committed
Sep 11, 2019
fb3ebfbb
filters: Add dates to FormValue
· 695976f8
Lowik BOURGEOISAT
authored
Jul 19, 2019
and
hydrargyrum
committed
Sep 11, 2019
695976f8
Hide whitespace changes
Inline
Side-by-side
weboob/browser/filters/html.py
View file @
695976f8
...
...
@@ -16,7 +16,8 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import
datetime
from
decimal
import
Decimal
import
lxml.html
as
html
from
six.moves.html_parser
import
HTMLParser
...
...
@@ -180,12 +181,31 @@ def filter(self, el):
if
el
.
attrib
.
get
(
'
type
'
)
in
(
'
radio
'
,
'
checkbox
'
):
return
'
checked
'
in
el
.
attrib
# regular text input
elif
el
.
attrib
.
get
(
'
type
'
,
''
)
in
(
''
,
'
text
'
,
'
email
'
,
'
search
'
,
'
tel
'
,
'
url
'
,
'
password
'
,
'
hidden
'
):
elif
el
.
attrib
.
get
(
'
type
'
,
''
)
in
(
''
,
'
text
'
,
'
email
'
,
'
search
'
,
'
tel
'
,
'
url
'
,
'
password
'
,
'
hidden
'
,
'
color
'
):
try
:
return
unicode
(
el
.
attrib
[
'
value
'
])
except
KeyError
:
return
self
.
default_or_raise
(
AttributeNotFound
(
'
Element %s does not have attribute value
'
%
el
))
# TODO handle html5 number, datetime, etc.
# numeric input
elif
el
.
attrib
.
get
(
'
type
'
,
''
)
in
(
'
number
'
,
'
range
'
):
try
:
if
'
.
'
in
el
.
attrib
.
get
(
'
step
'
,
''
):
return
Decimal
(
el
.
attrib
[
'
value
'
])
else
:
return
int
(
el
.
attrib
[
'
value
'
])
except
KeyError
:
return
self
.
default_or_raise
(
AttributeNotFound
(
'
Element %s does not have attribute value
'
%
el
))
# datetime input
try
:
if
el
.
attrib
.
get
(
'
type
'
,
''
)
==
'
date
'
:
return
datetime
.
datetime
.
strptime
(
el
.
attrib
[
'
value
'
],
'
%Y-%m-%d
'
).
date
()
elif
el
.
attrib
.
get
(
'
type
'
,
''
)
==
'
time
'
:
return
datetime
.
datetime
.
strptime
(
el
.
attrib
[
'
value
'
],
'
%H:%M
'
).
time
()
elif
el
.
attrib
.
get
(
'
type
'
,
''
)
==
'
datetime-local
'
:
return
datetime
.
datetime
.
strptime
(
el
.
attrib
[
'
value
'
],
'
%Y-%m-%dT%H:%M
'
)
except
KeyError
:
return
self
.
default_or_raise
(
AttributeNotFound
(
'
Element %s does not have attribute value
'
%
el
))
else
:
raise
UnrecognizedElement
(
'
Element %s is not recognized
'
%
el
)
elif
el
.
tag
==
'
textarea
'
:
...
...
weboob/browser/tests/filters.py
View file @
695976f8
...
...
@@ -15,10 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import
datetime
from
decimal
import
Decimal
from
unittest
import
TestCase
from
lxml.html
import
fromstring
from
weboob.browser.filters.html
import
Link
from
weboob.browser.filters.html
import
FormValue
,
Link
from
weboob.browser.filters.standard
import
RawText
...
...
@@ -51,6 +53,36 @@ def test_first_node_is_element_recursive(self):
self
.
assertEqual
(
"
229,90 EUR
"
,
RawText
(
'
//p
'
,
default
=
"
foo
"
,
children
=
True
)(
e
))
class
FormValueTest
(
TestCase
):
def
setUp
(
self
):
self
.
e
=
fromstring
(
'''
<form>
<input value=
"
bonjour
"
name=
"
test_text
"
>
<input type=
"
number
"
value=
"
5
"
name=
"
test_number1
"
>
<input type=
"
number
"
step=
"
0.01
"
value=
"
0.05
"
name=
"
test_number2
"
>
<input type=
"
checkbox
"
checked=
"
on
"
name=
"
test_checkbox1
"
>
<input type=
"
checkbox
"
name=
"
test_checkbox2
"
>
<input type=
"
range
"
value=
"
20
"
name=
"
test_range
"
>
<input type=
"
color
"
value=
"
#fff666
"
name=
"
test_color
"
>
<input type=
"
date
"
value=
"
2010-11-12
"
name=
"
test_date
"
>
<input type=
"
time
"
value=
"
12:13
"
name=
"
test_time
"
>
<input type=
"
datetime-local
"
value=
"
2010-11-12T13:14
"
name=
"
test_datetime_local
"
>
</form>
'''
)
def
test_value
(
self
):
self
.
assertEqual
(
'
bonjour
'
,
FormValue
(
'
//form//input[@name=
"
test_text
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
5
,
FormValue
(
'
//form//input[@name=
"
test_number1
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
Decimal
(
'
0.05
'
),
FormValue
(
'
//form//input[@name=
"
test_number2
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
True
,
FormValue
(
'
//form//input[@name=
"
test_checkbox1
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
False
,
FormValue
(
'
//form//input[@name=
"
test_checkbox2
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
20
,
FormValue
(
'
//form//input[@name=
"
test_range
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
'
#fff666
'
,
FormValue
(
'
//form//input[@name=
"
test_color
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
datetime
.
date
(
2010
,
11
,
12
),
FormValue
(
'
//form//input[@name=
"
test_date
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
datetime
.
time
(
12
,
13
),
FormValue
(
'
//form//input[@name=
"
test_time
"
]
'
)(
self
.
e
))
self
.
assertEqual
(
datetime
.
datetime
(
2010
,
11
,
12
,
13
,
14
),
FormValue
(
'
//form//input[@name=
"
test_datetime_local
"
]
'
)(
self
.
e
))
class
LinkTest
(
TestCase
):
def
test_link
(
self
):
e
=
fromstring
(
'
<a href=
"
https://www.google.com/
"
>Google</a>
'
)
...
...