本文整理汇总了Python中utils.Util.find方法的典型用法代码示例。如果您正苦于以下问题:Python Util.find方法的具体用法?Python Util.find怎么用?Python Util.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Util
的用法示例。
在下文中一共展示了Util.find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import find [as 别名]
class Account:
addon = xbmcaddon.Addon()
username = ''
password = ''
session_key = ''
icon = os.path.join(addon.getAddonInfo('path'), 'icon.png')
verify = False
def __init__(self):
self.username = self.addon.getSetting('username')
self.password = self.addon.getSetting('password')
self.session_key = self.addon.getSetting('session_key')
self.util = Util()
def login(self):
# Check if username and password are provided
if self.username == '':
dialog = xbmcgui.Dialog()
username = dialog.input('Please enter your username', type=xbmcgui.INPUT_ALPHANUM)
self.addon.setSetting(id='username', value=username)
if self.password == '':
dialog = xbmcgui.Dialog()
password = dialog.input('Please enter your password', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
self.addon.setSetting(id='password', value=password)
if self.username == '' or self.password == '':
sys.exit()
else:
url = 'https://secure.mlb.com/pubajaxws/services/IdentityPointService'
headers = {
"SOAPAction": "http://services.bamnetworks.com/registration/identityPoint/identify",
"Content-type": "text/xml; charset=utf-8",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Hub Build/MHC19J)",
"Connection": "Keep-Alive"
}
payload = "<?xml version='1.0' encoding='UTF-8'?>"
payload += '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
payload += '<SOAP-ENV:Body><tns:identityPoint_identify_request xmlns:tns="http://services.bamnetworks.com/registration/types/1.4">'
payload += '<tns:identification type="email-password"><tns:id xsi:nil="true"/>'
payload += '<tns:fingerprint xsi:nil="true"/>'
payload += '<tns:email>'
payload += '<tns:id xsi:nil="true"/>'
payload += '<tns:address>' + self.username + '</tns:address>'
payload += '</tns:email>'
payload += '<tns:password>' + self.password + '</tns:password>'
payload += '<tns:mobilePhone xsi:nil="true"/>'
payload += '<tns:profileProperty xsi:nil="true"/>'
payload += '</tns:identification>'
payload += '</tns:identityPoint_identify_request>'
payload += '</SOAP-ENV:Body>'
payload += '</SOAP-ENV:Envelope>'
r = requests.post(url, headers=headers, data=payload, verify=self.verify)
"""
Bad username => <status><code>-1000</code><message> [Invalid credentials for identification] [com.bamnetworks.registration.types.exception.IdentificationException: Account doesn't exits]</message><exceptionClass>com.bamnetworks.registration.types.exception.IdentificationException</exceptionClass><detail type="identityPoint" field="exists" message="false" messageKey="identityPoint.exists" /><detail type="identityPoint" field="email-password" message="identification error on identity point of type email-password" messageKey="identityPoint.email-password" /></status>
Bad password => <status><code>-1000</code><message> [Invalid credentials for identification] [com.bamnetworks.registration.types.exception.IdentificationException: Invalid Password]</message><exceptionClass>com.bamnetworks.registration.types.exception.IdentificationException</exceptionClass><detail type="identityPoint" field="exists" message="true" messageKey="identityPoint.exists" /><detail type="identityPoint" field="email-password" message="identification error on identity point of type email-password" messageKey="identityPoint.email-password" /></status>
Good => <status><code>1</code><message>OK</message></status>
"""
if self.util.find(r.text, '<code>', '</code>') != '1':
title = self.util.find(r.text, '<message> [', '] [')
msg = self.util.find(r.text, 'com.bamnetworks.registration.types.exception.IdentificationException: ', ']</message>')
dialog = xbmcgui.Dialog()
dialog.ok(title, msg)
sys.exit()
else:
self.util.save_cookies(r.cookies)
def feature_service(self):
if self.util.check_cookies():
self.login()
cookies = requests.utils.dict_from_cookiejar(self.util.load_cookies())
url = 'https://secure.mlb.com/pubajaxws/services/FeatureService'
headers = {
"SOAPAction": "http://services.bamnetworks.com/registration/feature/findEntitledFeatures",
"Content-type": "text/xml; charset=utf-8",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Hub Build/MHC19J)",
"Connection": "Keep-Alive"
}
payload = "<?xml version='1.0' encoding='UTF-8'?>"
payload += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'
payload += '<soapenv:Header />'
payload += '<soapenv:Body>'
payload += '<feature_findEntitled_request xmlns="http://services.bamnetworks.com/registration/types/1.6">'
if 'ipid' in cookies and 'fprt' in cookies and self.session_key != '':
payload += "<identification type='fingerprint'>"
payload += '<id>' + cookies['ipid'] + '</id>'
payload += '<fingerprint>' + cookies['fprt'] + '</fingerprint>'
payload += "<signOnRestriction type='mobileApp'>"
payload += '<location>ANDROID_21d994bd-ebb1-4253-bcab-3550e7882294</location>'
payload += '<sessionKey>' + self.session_key + '</sessionKey>'
else:
payload += "<identification type='email-password'>"
payload += '<email><address>' + self.username + '</address></email>'
payload += '<password>' + self.password + '</password>'
payload += '<signOnRestriction type="mobileApp">'
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import find [as 别名]
class Account:
addon = xbmcaddon.Addon()
username = ''
password = ''
session_key = ''
icon = os.path.join(addon.getAddonInfo('path'), 'icon.png')
verify = False
def __init__(self):
self.username = self.addon.getSetting('username')
self.password = self.addon.getSetting('password')
self.session_key = self.addon.getSetting('session_key')
self.util = Util()
def login(self):
# Check if username and password are provided
if self.username == '':
dialog = xbmcgui.Dialog()
username = dialog.input('Please enter your username', type=xbmcgui.INPUT_ALPHANUM)
self.addon.setSetting(id='username', value=username)
if self.password == '':
dialog = xbmcgui.Dialog()
password = dialog.input('Please enter your password', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
self.addon.setSetting(id='password', value=password)
if self.username == '' or self.password == '':
sys.exit()
else:
url = 'https://secure.mlb.com/pubajaxws/services/IdentityPointService'
headers = {
"SOAPAction": "http://services.bamnetworks.com/registration/identityPoint/identify",
"Content-type": "text/xml; charset=utf-8",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Hub Build/MHC19J)",
"Connection": "Keep-Alive"
}
payload = "<?xml version='1.0' encoding='UTF-8'?>"
payload += '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
payload += '<SOAP-ENV:Body><tns:identityPoint_identify_request xmlns:tns="http://services.bamnetworks.com/registration/types/1.4">'
payload += '<tns:identification type="email-password"><tns:id xsi:nil="true"/>'
payload += '<tns:fingerprint xsi:nil="true"/>'
payload += '<tns:email>'
payload += '<tns:id xsi:nil="true"/>'
payload += '<tns:address>' + self.username + '</tns:address>'
payload += '</tns:email>'
payload += '<tns:password>' + self.password + '</tns:password>'
payload += '<tns:mobilePhone xsi:nil="true"/>'
payload += '<tns:profileProperty xsi:nil="true"/>'
payload += '</tns:identification>'
payload += '</tns:identityPoint_identify_request>'
payload += '</SOAP-ENV:Body>'
payload += '</SOAP-ENV:Envelope>'
r = requests.post(url, headers=headers, data=payload, verify=self.verify)
"""
Bad username => <status><code>-1000</code><message> [Invalid credentials for identification] [com.bamnetworks.registration.types.exception.IdentificationException: Account doesn't exits]</message><exceptionClass>com.bamnetworks.registration.types.exception.IdentificationException</exceptionClass><detail type="identityPoint" field="exists" message="false" messageKey="identityPoint.exists" /><detail type="identityPoint" field="email-password" message="identification error on identity point of type email-password" messageKey="identityPoint.email-password" /></status>
Bad password => <status><code>-1000</code><message> [Invalid credentials for identification] [com.bamnetworks.registration.types.exception.IdentificationException: Invalid Password]</message><exceptionClass>com.bamnetworks.registration.types.exception.IdentificationException</exceptionClass><detail type="identityPoint" field="exists" message="true" messageKey="identityPoint.exists" /><detail type="identityPoint" field="email-password" message="identification error on identity point of type email-password" messageKey="identityPoint.email-password" /></status>
Good => <status><code>1</code><message>OK</message></status>
"""
if self.util.find(r.text, '<code>', '</code>') != '1':
title = self.util.find(r.text, '<message> [', '] [')
msg = self.util.find(r.text, 'com.bamnetworks.registration.types.exception.IdentificationException: ', ']</message>')
dialog = xbmcgui.Dialog()
dialog.ok(title, msg)
sys.exit()
else:
self.util.save_cookies(r.cookies)
def feature_service(self):
if self.util.check_cookies():
self.login()
cookies = requests.utils.dict_from_cookiejar(self.util.load_cookies())
url = 'https://secure.mlb.com/pubajaxws/services/FeatureService'
headers = {
"SOAPAction": "http://services.bamnetworks.com/registration/feature/findEntitledFeatures",
"Content-type": "text/xml; charset=utf-8",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Hub Build/MHC19J)",
"Connection": "Keep-Alive"
}
payload = "<?xml version='1.0' encoding='UTF-8'?>"
payload += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'
payload += '<soapenv:Header />'
payload += '<soapenv:Body>'
payload += '<feature_findEntitled_request xmlns="http://services.bamnetworks.com/registration/types/1.6">'
if 'ipid' in cookies and 'fprt' in cookies and self.session_key != '':
payload += "<identification type='fingerprint'>"
payload += '<id>' + cookies['ipid'] + '</id>'
payload += '<fingerprint>' + cookies['fprt'] + '</fingerprint>'
payload += "<signOnRestriction type='mobileApp'>"
payload += '<location>ANDROID_21d994bd-ebb1-4253-bcab-3550e7882294</location>'
payload += '<sessionKey>' + self.session_key + '</sessionKey>'
else:
payload += "<identification type='email-password'>"
payload += '<email><address>' + self.username + '</address></email>'
payload += '<password>' + self.password + '</password>'
payload += '<signOnRestriction type="mobileApp">'
#.........这里部分代码省略.........