def find_decl_doc(self, name):
raise IncludeError(name)
import requests
from requests.exceptions import InvalidSchema
url = METATAB_ASSETS_URL + name + '.csv'
try:
# See if it exists online in the official repo
r = requests.head(url, allow_redirects=False)
if r.status_code == requests.codes.ok:
return url
except InvalidSchema:
pass # It's probably FTP
python类InvalidSchema()的实例源码
def test_connerror_invalid_url_schema(self):
# GIVEN server url with invalid 'htt:' schema
self.config['server'] = 'htt://127.0.0.1'
# WHEN dpm publish is invoked
try:
result = self.invoke(cli, ['publish', ])
except Exception as e:
result = e
# THEN InvalidSchema should be raised
assert isinstance(result, InvalidSchema)
# AND it should say that schema is invalid
assert "No connection adapters were found for 'htt://127.0.0.1/api/auth/token'" in str(result)
def raiseLostAuth(f):
@wraps(f)
def lost_auth_wrapper(*args,**kwargs):
try:
f(args,**kwargs)
except InvalidSchema as e:
if re.search(r'steammobile://lostauth',e.message) is not None:
raise SteamExceptions.LostAuthException("Login was lost, relog again")
return lost_auth_wrapper
def md5_sum_from_url(url):
try:
r = requests.get(url, stream=True)
except InvalidSchema:
return None
except MissingSchema:
return None
chunk_counter = 0
hash_store = hashlib.md5()
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
hash_store.update(chunk)
chunk_counter += 1
# It is not possible to send greater than 50 MB via Telegram
if chunk_counter > 50 * 1024:
return None
return hash_store.hexdigest()
def load_synonyms(path):
try:
r = requests.get(path)
content = r.text
except (MissingSchema, InvalidSchema, InvalidURL):
try:
with open(path, encoding='utf-8') as fp:
content = fp.read()
except (OSError, IOError):
raise TypeError('Invalid Path: "{0}". Ensure it is either a URL or Correct FS Path.'.format(path))
return SynParser.get_mapping(content)