def recipes_ending(language: StrictStr, ending: StrictStr): """ Show the recipe for a word-ending. Given an input language and an ending, present the user with the recipe that will be used to build grammatical cases for that specific ending. And this path operation will: * returns a single recipe for the ending specific in the path """ try: recipes = Recipes(language=language.lower()) recipes.load() if ending not in recipes._dict.keys(): raise HTTPException( status_code=HTTP_404_NOT_FOUND, detail="Ending not found" ) return {"language": language, "ending": ending, "recipe": recipes._dict[ending]} except LanguageNotFoundError: raise HTTPException( status_code=HTTP_404_NOT_FOUND, detail=f"Language: {language} not found." )
def cli(ctx, config_path, broadcast: bool): config = parse_config(ctx, config_path, Config) config.contract_bin = StrictStr( file_validator(config.contract_bin, config_path)) constructor_data = "" if config.constructor_types and config.constructor_values: constructor_types = yaml.full_load(config.constructor_types) constructor_values = yaml.full_load(config.constructor_values) constructor_data = eth_abi.encode_data(constructor_types, constructor_values)[2:] if ctx.obj.get("config"): # noinspection PyUnresolvedReferences print_json(config.dict() | {"constructor_data": constructor_data}) exit(0) tx_params: Any = pydash.omit(config.dict(), "node", "contract_bin", "constructor_types", "constructor_values") tx_params["data"] = config.contract_bin + constructor_data if tx_params["nonce"] is None: tx_params["nonce"] = get_nonce_or_exit( config.node, eth_account.private_to_address(config.private_key)) signed_tx = eth_tx.sign_tx(**tx_params) if broadcast: res = eth_rpc.eth_send_raw_transaction(config.node, signed_tx.raw_tx) print_json({"result": res.ok_or_error}) else: decoded = eth_utils.to_human_readable_tx( eth_tx.decode_raw_tx(signed_tx.raw_tx)) print_json(signed_tx.dict() | {"decoded": decoded})
def __init__( self, nlp: Language, name: str, value1: StrictInt = StrictInt(10), value2: StrictStr = StrictStr("hello"), ): self.nlp = nlp self.value1 = value1 self.value2 = value2
async def parse_source(url: AnyUrl = Query(default=None, title="URI источника данных", description=_descr_source), file: UploadFile = File( default=..., title="Файл DBF", description="Файл формата dBase(3/4)")): format_packet = await parse_format(url=url, file=file) dbf_bytes = await unpack(value=file, dont_close_after_read=False, content_type=await ContentType.from_str(StrictStr(file.content_type) )) dbf = await bssapi.core.dbf.get_dbf(dbf_bytes) source_packet = bssapi.schemas.exch.build_packet( format_packet=format_packet, dbf=dbf, dbf_bytes=dbf_bytes, file=file) dbf.unload() return source_packet
def recipes_language(language: StrictStr): """ Show available Recipes for language. This will show the Recipes for the input language to the user. It is a collection of recipes on how to construct grammatical cases for an input word. And this path operation will: * return the entire collection of recipes """ try: recipes = Recipes(language=language.lower()) recipes.load() return {"language": language, "recipes": recipes._dict} except LanguageNotFoundError: raise HTTPException( status_code=HTTP_404_NOT_FOUND, detail=f"Language: {language} not found." )
async def unpack(content_type: ContentType, value: UploadFile, dont_close_after_read=typing.Any) -> StrBytes: await value.seek(0) _value = await value.read() if dont_close_after_read: await value.close() else: await value.seek(0) try: if 'base64' in content_type.params: _value = multipart.multipart.base64.standard_b64decode(_value) if 'lz4' in content_type.params: _value = lz4.block.decompress(source=_value) except BaseException as exc: raise RequestValidationError(errors=[ pydantic.error_wrappers.ErrorWrapper(exc=ValueError( 'Не могу распаковать содержиме файла.', StrictStr(exc)), loc=("body", "params")) ], body=ContentType) return _value
class TokenPatternOperatorSimple(str, Enum): plus: StrictStr = StrictStr("+") star: StrictStr = StrictStr("*") question: StrictStr = StrictStr("?") exclamation: StrictStr = StrictStr("!")
async def parse_format( url: AnyUrl = Query(default=None, title="URI источника данных", description=_descr_source), file: UploadFile = File(default=..., title="Файл DBF", description="Файл формата dBase(3/4)"), request: Request = None): content_type = await ContentType.from_str(StrictStr(file.content_type)) if content_type.type == "application/octet-stream": dbf_bytes = await unpack(value=file, content_type=content_type, dont_close_after_read=request) ext = PurePosixPath(file.filename).suffix.lower() if ext in ['.dbf']: dbf = None try: dbf = await bssapi.core.dbf.get_dbf(dbf_bytes) if len( dbf_bytes) else None except BaseException as exc: raise RequestValidationError(errors=[ pydantic.error_wrappers.ErrorWrapper(exc=ValueError( 'Не могу открыть файл.', StrictStr(exc)), loc=("body", "file")) ], body={"file": file.filename}) else: if isinstance(dbf, DBF): format_packet = await bssapi.schemas.exch.build_format( url=url, fields=dbf.fields) dbf.unload() return format_packet else: raise RequestValidationError(errors=[ pydantic.error_wrappers.ErrorWrapper( exc=ValueError('Не могу открыть файл.'), loc=("body", "file")) ], body={"file": file.filename}) else: raise RequestValidationError(errors=[ pydantic.error_wrappers.ErrorWrapper( exc=ValueError('Не верное расширение файла'), loc=("body", "filename", "extension")) ], body={ "filename": { "extension": ext, "filename": file.filename } }) else: raise RequestValidationError(errors=[ pydantic.error_wrappers.ErrorWrapper(exc=ValueError( "Не верный тип содержимого тела запроса. Ожидалось 'application/octet-stream'" ), loc=("body", "Сontent-type")) ], body={"Сontent-type": file.content_type})
async def from_str(cls, content_type: StrictStr): content_type, *content_params = content_type.split(';') return cls(type=content_type, params=content_params)
def path(cls, base_url: AnyHttpUrl) -> AnyHttpUrl: base_url += "/odata/standard.odata/InformationRegister_{InformationRegister}?$format=json" \ .format(InformationRegister=cls.__name__) return cls._get_url(base_url=StrictStr(base_url))