本文整理汇总了Python中urllib2.Request.lower方法的典型用法代码示例。如果您正苦于以下问题:Python Request.lower方法的具体用法?Python Request.lower怎么用?Python Request.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.lower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_json_data
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import lower [as 别名]
def _validate_json_data(json_data):
# Here we are validating the followings:
# 1. date values are actually date type data and the beginDate <= endDate
# 2. 'url' is valid and live if the url value is not none or 'unknown' (case insensitive)
# 3. 'sampleMedium' is not empty string
# 4. 'variableName' is not empty string
# 5. 'title' is not empty string
# 6. 'abstract' is not empty string
# 7. 'fileVersion' is not empty string
# 8. 'symbol' is not empty string
# 9. 'siteName' is not empty string
# 10. 'methodLink' is not empty string
# 11. 'methodDescription' is not empty string
err_msg = "Invalid json file. {}"
# validate title
_check_for_empty_string(json_data['timeSeriesReferenceFile']['title'], 'title')
# validate abstract
_check_for_empty_string(json_data['timeSeriesReferenceFile']['abstract'], 'abstract')
# validate fileVersion
_check_for_empty_string(json_data['timeSeriesReferenceFile']['fileVersion'], 'fileVersion')
# validate symbol
_check_for_empty_string(json_data['timeSeriesReferenceFile']['symbol'], 'symbol')
series_data = json_data['timeSeriesReferenceFile']['referencedTimeSeries']
urls = []
for series in series_data:
try:
start_date = parser.parse(series['beginDate'])
end_date = parser.parse(series['endDate'])
except Exception:
raise Exception(err_msg.format("Invalid date values"))
if timezone.is_aware(start_date):
start_date = timezone.make_naive(start_date)
if timezone.is_aware(end_date):
end_date = timezone.make_naive(end_date)
if start_date > end_date:
raise Exception(err_msg.format("Invalid date values"))
# validate requestInfo object
request_info = series["requestInfo"]
# validate refType
if request_info['refType'] not in RefTimeseriesLogicalFile.get_allowed_ref_types():
raise ValidationError("Invalid value for refType")
# validate returnType
if request_info['returnType'] not in RefTimeseriesLogicalFile.get_allowed_return_types():
raise ValidationError("Invalid value for returnType")
# validate serviceType
if request_info['serviceType'] not in RefTimeseriesLogicalFile.get_allowed_service_types():
raise ValidationError("Invalid value for serviceType")
# check valueCount is not a negative number
if series['valueCount'] is not None and series['valueCount'] < 0:
raise ValidationError("valueCount can't be a negative number")
# check that sampleMedium
_check_for_empty_string(series['sampleMedium'], 'sampleMedium')
# validate siteName
_check_for_empty_string(series['site']['siteName'], 'siteName')
# validate variableName
_check_for_empty_string(series['variable']['variableName'], 'variableName')
url = Request(request_info['url'])
if url not in urls:
urls.append(url)
try:
urlopen(url)
except URLError:
raise Exception(err_msg.format("Invalid web service URL found"))
# validate methodDescription for empty string
_check_for_empty_string(series['method']['methodDescription'], 'methodDescription')
# validate methodLink
if series['method']['methodLink'] is not None:
url = series['method']['methodLink'].strip()
if not url:
raise ValidationError("methodLink has a value of empty string")
if url.lower() != 'unknown':
url = Request(url)
if url not in urls:
urls.append(url)
try:
urlopen(url)
except URLError:
raise Exception(err_msg.format("Invalid method link found"))