本文整理汇总了Python中typing_extensions.TypedDict方法的典型用法代码示例。如果您正苦于以下问题:Python typing_extensions.TypedDict方法的具体用法?Python typing_extensions.TypedDict怎么用?Python typing_extensions.TypedDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing_extensions
的用法示例。
在下文中一共展示了typing_extensions.TypedDict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __post_init__
# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import TypedDict [as 别名]
def __post_init__(self) -> None:
""""Validate that the extra arguments match the scan commands.
"""
if not self.scan_commands_extra_arguments:
return
for scan_command in self.scan_commands_extra_arguments:
if scan_command not in self.scan_commands:
raise ValueError(f"Received an extra argument for a scan command that wasn't enabled: {scan_command}")
# TypedDict for simpler/matching JSON output and makes fetching a field easier
示例2: dropbox_image
# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import TypedDict [as 别名]
def dropbox_image(self, url: str) -> Optional[Dict[str, Any]]:
# TODO: The returned Dict could possibly be a TypedDict in future.
parsed_url = urllib.parse.urlparse(url)
if (parsed_url.netloc == 'dropbox.com' or parsed_url.netloc.endswith('.dropbox.com')):
is_album = parsed_url.path.startswith('/sc/') or parsed_url.path.startswith('/photos/')
# Only allow preview Dropbox shared links
if not (parsed_url.path.startswith('/s/') or
parsed_url.path.startswith('/sh/') or
is_album):
return None
# Try to retrieve open graph protocol info for a preview
# This might be redundant right now for shared links for images.
# However, we might want to make use of title and description
# in the future. If the actual image is too big, we might also
# want to use the open graph image.
image_info = fetch_open_graph_image(url)
is_image = is_album or self.is_image(url)
# If it is from an album or not an actual image file,
# just use open graph image.
if is_album or not is_image:
# Failed to follow link to find an image preview so
# use placeholder image and guess filename
if image_info is None:
return None
image_info["is_image"] = is_image
return image_info
# Otherwise, try to retrieve the actual image.
# This is because open graph image from Dropbox may have padding
# and gifs do not work.
# TODO: What if image is huge? Should we get headers first?
if image_info is None:
image_info = dict()
image_info['is_image'] = True
parsed_url_list = list(parsed_url)
parsed_url_list[4] = "dl=1" # Replaces query
image_info["image"] = urllib.parse.urlunparse(parsed_url_list)
return image_info
return None