def create_example_frontier_response(uuid=v.sample_uuid): frontier_one = pyd_models.Frontier( fqdn=example_domain_com, tld="com", url_list=[ pyd_models.Url( url=HttpUrl(url="https://www.example.com/abcefg", scheme="http", host="example"), fqdn=example_domain_com, ), pyd_models.Url( url=HttpUrl(url="https://www.example.com/hijklm", scheme="http", host="example"), fqdn=example_domain_com, ), ], ) frontier_two = pyd_models.Frontier( fqdn=example_domain_de, tld="de", url_list=[ pyd_models.Url( url=HttpUrl(url="https://www.example.de/abcefg", scheme="http", host="example"), fqdn=example_domain_de, ), pyd_models.Url( url=HttpUrl(url="https://www.example.de/hijklm", scheme="http", host="example"), fqdn=example_domain_de, ), ], ) frontier_response = pyd_models.FrontierResponse( uuid=uuid, response_url="https://www.example.com/submit?code=1234567890", latest_return=rand_gen.random_datetime(), url_frontiers=[frontier_one, frontier_two], ) frontier_response.url_frontiers_count = len( frontier_response.url_frontiers) urls_count = 0 for url_frontier in frontier_response.url_frontiers: urls_count += len(url_frontier.url_list) frontier_response.urls_count = urls_count return frontier_response
def generate_example_submission(uuid): frontier_one = pyd_models.Frontier( fqdn=example_domain_com, tld="com", fqdn_last_ipv4="123.123.123.123", url_list=[ pyd_models.Url( url=HttpUrl(url="https://www.example.com/abcefg", scheme="http", host="example"), fqdn=example_domain_com, url_last_visited=datetime.now(), ), pyd_models.Url( url=HttpUrl(url="https://www.example.com/hijklm", scheme="http", host="example"), fqdn=example_domain_com, url_last_visited=datetime.now(), ), ], ) frontier_two = pyd_models.Frontier( fqdn=example_domain_de, tld="de", url_list=[ pyd_models.Url( url=HttpUrl(url="https://www.example.de/abcefg", scheme="http", host="example"), fqdn=example_domain_de, ), pyd_models.Url( url=HttpUrl(url="https://www.example.de/hijklm", scheme="http", host="example"), fqdn=example_domain_de, ), ], ) submit_frontier = pyd_models.SubmitFrontier( uuid=uuid, url_frontiers=[frontier_one, frontier_two], ) return submit_frontier
async def GMHandler(app: Mirai, group: Group, member: Member, message: GroupMessage): print(message) print(message.toString()) global RECORDS, STATUS if "醒醒不对劲" in message.toString(): STATUS = True await app.sendGroupMessage(group, [Plain(text="我还想再睡会儿!")]) if not STATUS: return if "报名" in message.toString(): try: message_handler(member, message.toString()) await app.sendGroupMessage(group, [Plain(text=format_table())]) except Exception: await app.sendGroupMessage(group, [Plain(text="糟糕,坑满啦!")]) elif "clear" in message.toString(): RECORDS = {} await app.sendGroupMessage(group, [Plain(text=format_table())]) elif "出来吧憨憨" in message.toString(): time.sleep(1) await app.sendGroupMessage(group, [Plain(text="余目才是憨批!")]) elif message.toString() == "/roll": await app.sendGroupMessage(group, [Plain(text=str(random.randint(0, 100)))]) elif "At::target=75960775" in message.toString(): if random.randint(0, 10) < 4: await app.sendGroupMessage( group, [Plain(text="喊我干啥,我又不是小爱同学"), Face(faceId=QQFaces['nanguo'])]) else: await app.sendGroupMessage(group, [Plain(text=random_words())]) elif "睡吧不对劲" in message.toString(): STATUS = False await app.sendGroupMessage(group, [ Plain(text="晚安~"), Image( type='Image', imageId='AD698F3D-FCEC-0516-C6DA-346967FF876E', url=HttpUrl( 'http://gchat.qpic.cn/gchatpic_new/843452214/1032083209-2934067879-AD698F3DFCEC0516C6DA346967FF876E/0?term=2', scheme='http', host='gchat.qpic.cn', tld='cn', host_type='domain', path= '/gchatpic_new/843452214/1032083209-2934067879-AD698F3DFCEC0516C6DA346967FF876E/0', query='term=2')) ]) else: num = random.randint(0, 100) if num < 10: time.sleep(1) await app.sendGroupMessage(group, [Plain(text=random_words())]) if random.randint(0, 100) < 30 and "At::target" not in message.toString(): WORDS.append(message.toString())
def validate_repo_url(cls, v: HttpUrl) -> HttpUrl: if v.path and v.path.endswith(".git"): v.path = v.path[:-4] return HttpUrl.build( scheme=v.scheme, user=v.user, password=v.password, host=v.host, tld=v.tld, host_type=v.host_type, port=v.port, path=v.path, query=v.query, fragment=v.fragment, ) return v
def validate_url(cls, v: HttpUrl) -> HttpUrl: if v.path is None: v.path = "/" return HttpUrl.build( scheme=v.scheme, user=v.user, password=v.password, host=v.host, tld=v.tld, host_type=v.host_type, port=v.port, path=v.path, query=v.query, fragment=v.fragment, ) return v
def test_get_url_from_frontier_response(): frontier_response = create_example_frontier_response() url_list = frontier.get_url_list_from_frontier_response(frontier_response) assert frontier_response.url_frontiers_count == 2 assert frontier_response.urls_count == 4 assert url_list == [ HttpUrl(url="https://www.example.com/abcefg", scheme="http", host="example"), HttpUrl(url="https://www.example.com/hijklm", scheme="http", host="example"), HttpUrl(url="https://www.example.de/abcefg", scheme="http", host="example"), HttpUrl(url="https://www.example.de/hijklm", scheme="http", host="example"), ]
def get_rem_by_name( self, name: str, parent_id: Optional[RemId] = None, ) -> Union[Rem, None]: """Get a Rem by its name.""" rem: Optional[Rem] = None log.debug(f"Searching Rem (name '{name}')...'") # search in cache try: rem = next( rem for rem in self._rem_cache.values() if name in rem.name # NOTE: Rems usually have their texts altered by RemNote, and # should not match - even if the original name is identical ) assert rem # force change in cache order self._rem_cache[rem.rem_id] # pylint: disable=pointless-statement except StopIteration: pass else: log.debug(f"Got Rem: '{rem.name[0]}' (#{rem.rem_id}) from cache.") return rem # define request endpoint: HttpUrl = HttpUrl(RemNoteV0Client.base_url + "/get_by_name") data = { "apiKey": self._key, "userId": self._user_id, "name": name, "parentId": parent_id, } # post data response: Response = self._session.post(endpoint, data) # check response status if response.status_code != 200: log.error(f"Failed to fetch Rem. Error {response.status_code}") raise HTTPError found = response.json().pop("found", False) if not found: log.warn(f"No Rem found with name '{name}' in current scope.") else: rem = Rem(**response.json()) self._rem_cache[rem.rem_id] = rem # add to cache log.debug(f"Got Rem: '{rem.name[0]}' (#{rem.rem_id}) from server.") return rem
def validate( cls, value: Any, field: ModelField, config: BaseConfig ) -> Orcid: if value.__class__ == cls: return value m = ORCID_PATTERN.search(value) if not m: raise OrcidError() identifier = m["identifier"] if not cls.verify_checksum(identifier): raise OrcidError() return HttpUrl.validate( f"https://orcid.org/{identifier}", field, config )
async def add_song(url: HttpUrl): """ add new song by url """ # check if duplicate url = url.split("&")[0] # drop additional query terms if await is_duplicate_url(url): return JSONResponse(status_code=400, content={"message": "duplicate"}) # fetch song requester = Requester(url) status = requester.fetch() if status != "done": return JSONResponse(status_code=400, content={"message": "invalid url"}) # add to database song = SongsModel(**requester.song) return await add_to_database(song)
def validate( cls, value: Any, field: ModelField, config: BaseConfig ) -> Ror: if value.__class__ == cls: return value m = ROR_PATTERN.search(value) if not m: print("pattern did not match") raise RorError() identifier = m["identifier"] try: base32.decode(identifier, checksum=True) except ValueError: raise RorError() return HttpUrl.validate(value, field, config)
async def fetch_file_infos(self, id_: UUID, url: HttpUrl): self.logger.info("Fetch file infos: '%s'", url) response = requests.head(url) if response.status_code == 200: filename = url.split("/")[-1] self.command_bus.execute( UpdateFileInfosCommand( id_=id_, size=int(response.headers["Content-length"]), filename=filename, ), NullPresenter(), ) else: self.logger.warning("'%s' is offline", url) self.command_bus.execute( SetDownloadOfflineCommand(id_=id_), NullPresenter(), )
def build_sentry_dsn(cls, sentry_dsn: Optional[str]) -> Any: # noqa: N805 """Set SENTRY_DSN.""" if sentry_dsn: return HttpUrl(sentry_dsn) return None
def linkify_doi(doi: Dict[Literal["DOI", "id"], str]) -> Hyperlink: return Hyperlink(href=HttpUrl(doi["DOI"], scheme='https', host='doi.org'), title=doi["id"])
from pydantic import HttpUrl from fibsem_metadata.models.sources import VolumeSource from fibsem_metadata.models.metadata import Hyperlink, DatasetMetadata from fibsem_metadata.models.views import DatasetViews from pydantic import ValidationError import logging logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) pub_mapping = { 'Xu et al., 2020': Hyperlink(href=HttpUrl('https://doi.org/10.1038/s41586-021-03992-4', scheme='https', host='doi.org'), title='Xu et al., 2021'), 'Heinrich et al., 2020': Hyperlink(href=HttpUrl('https://doi.org/10.1038/s41586-021-03977-3', scheme='https', host='doi.org'), title='Heinrich et al., 2021'), 'Weigel, Chang, et al., 2021': Hyperlink(href=HttpUrl('https://doi.org/10.1016/j.cell.2021.03.035', scheme='https', host='doi.org'), title='Weigel, Chang, et al., 2021'), 'Ritter et al., 2021': Hyperlink(href=HttpUrl('about:blank', scheme='https', host='doi.org'), title='Ritter et al., 2022'),