FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-webuntis/webuntis/utils/userinput.py at master · python-webuntis/python-webuntis · GitHub
python-webuntis
/
python-webuntis
Public
Notifications
You must be signed in to change notification settings
Fork
21
Star
81
Code
Issues
4
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-webuntis
/
webuntis
/
utils
/
userinput.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (52 loc) · 1.75 KB
Breadcrumbs
python-webuntis
/
webuntis
/
utils
/
userinput.py
Copy path
File metadata and controls
66 lines (52 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
This file is part of python-webuntis
:copyright: (c) 2013 by Markus Unterwaditzer.
:license: BSD, see LICENSE for more details.
"""
import
re
from
.
logger
import
log
from
.
third_party
import
urlparse
def
server
(
url
):
if
not
re
.
match
(
r'^http(s?)://'
,
url
):
# if we just have the hostname
log
(
'debug'
,
'The URL given doesn
\'
t seem to be a valid URL, just '
'gonna prepend "https://"'
)
# append the http prefix and hope for the best
url
=
'https://'
+
url
urlobj
=
urlparse
.
urlparse
(
url
)
if
not
urlobj
.
scheme
or
not
urlobj
.
netloc
:
# urlparse failed
raise
ValueError
(
'Not a valid URL or hostname'
)
if
not
re
.
match
(
r'^[a-zA-Z0-9.:\-_]+$'
,
urlobj
.
netloc
):
# That's not even a valid hostname
raise
ValueError
(
'Not a valid hostname'
)
if
urlobj
.
path
==
'/'
:
log
(
'warning'
,
'You specified that the API endpoint should be "/".'
'That is uncommon. If you didn
\'
t mean to do so,'
'remove the slash at the end of your "server"'
'parameter.'
)
return
urlobj
.
scheme
+
\
u'://'
+
\
urlobj
.
netloc
+
\
(
urlobj
.
path
or
u'/WebUntis/jsonrpc.do'
)
def
string
(
value
):
"""Make the string unicode"""
if
isinstance
(
value
,
unicode_string
):
return
value
return
value
.
decode
(
'ascii'
)
config_keys
=
{
'username'
:
string
,
'password'
:
string
,
'jsessionid'
:
string
,
'school'
:
string
,
'server'
:
server
,
'useragent'
:
string
,
'login_repeat'
:
int
,
'_http_session'
:
None
}
try
:
# noinspection PyUnresolvedReferences
unicode_string
=
unicode
bytestring
=
str
except
NameError
:
unicode_string
=
str
bytestring
=
bytes
Back
|
FazBrowse Home
|
New Git URL