def validate_array(array): """ Builds a new array with valid values for the ShippingAddress constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") data = Result.validate_array(array) data['country_code'] = u(array.get('country_code')) data['state'] = u(array.get('state')) data['city'] = u(array.get('city')) data['street_line1'] = u(array.get('street_line1')) data['street_line2'] = u(array.get('street_line2')) data['post_code'] = u(array.get('post_code')) return data
def validate_array(array): """ Builds a new array with valid values for the PassportFile constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from ....datetime import datetime data = Result.validate_array(array) data['file_id'] = u(array.get('file_id')) data['file_unique_id'] = u(array.get('file_unique_id')) data['file_size'] = int(array.get('file_size')) data['file_date'] = datetime.from_array(array.get('file_date')) return data
def validate_array(array): """ Builds a new array with valid values for the GameHighScore constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.peer import User data = Result.validate_array(array) data['position'] = int(array.get('position')) data['user'] = User.from_array(array.get('user')) data['score'] = int(array.get('score')) return data
def validate_array(array): """ Builds a new array with valid values for the ShippingOption constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from . import LabeledPrice data = Sendable.validate_array(array) data['id'] = u(array.get('id')) data['title'] = u(array.get('title')) data['prices'] = LabeledPrice.from_array_list(array.get('prices'), list_level=1) return data
def validate_array(array): """ Builds a new array with valid values for the PassportData constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.passport import EncryptedCredentials from pytgbot.api_types.receivable.passport import EncryptedPassportElement data = Result.validate_array(array) data['data'] = EncryptedPassportElement.from_array_list( array.get('data'), list_level=1) data['credentials'] = EncryptedCredentials.from_array( array.get('credentials'))
def validate_array(array): """ Builds a new array with valid values for the OrderInfo constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from . import ShippingAddress data = Result.validate_array(array) data['name'] = u(array.get('name')) if array.get('name') is not None else None data['phone_number'] = u(array.get('phone_number')) if array.get('phone_number') is not None else None data['email'] = u(array.get('email')) if array.get('email') is not None else None data['shipping_address'] = ShippingAddress.from_array(array.get('shipping_address')) if array.get('shipping_address') is not None else None return data
def __init__(self, title, description, start_parameter, currency, total_amount, _raw=None): """ This object contains basic information about an invoice. https://core.telegram.org/bots/api#invoice Parameters: :param title: Product name :type title: str|unicode :param description: Product description :type description: str|unicode :param start_parameter: Unique bot deep-linking parameter that can be used to generate this invoice :type start_parameter: str|unicode :param currency: Three-letter ISO 4217 currency code :type currency: str|unicode :param total_amount: Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). :type total_amount: int Optional keyword parameters: :param _raw: Optional. Original data this object was generated from. Could be `None`. :type _raw: None | dict """ super(Invoice, self).__init__() assert_type_or_raise(title, unicode_type, parameter_name="title") self.title = title assert_type_or_raise(description, unicode_type, parameter_name="description") self.description = description assert_type_or_raise(start_parameter, unicode_type, parameter_name="start_parameter") self.start_parameter = start_parameter assert_type_or_raise(currency, unicode_type, parameter_name="currency") self.currency = currency assert_type_or_raise(total_amount, int, parameter_name="total_amount") self.total_amount = total_amount self._raw = _raw
def safe_eval(user_input, allowed_values=NoBuiltins(eval_safe_builtin_list, eval_safe_builtin_function_list)): """ Evals the `user_input` string. :param user_input: :param allowed_values: NoBuiltins object :type allowed_values: NoBuiltins :param question: :return: :raises NotAllowed: The :class:`NoBuiltins` raises a :class:`NotAllowed` Exception when the command is not allowed. """ assert_type_or_raise(user_input, str) assert isinstance(user_input, str) assert_type_or_raise(allowed_values, NoBuiltins) assert isinstance(allowed_values, NoBuiltins) result = eval(user_input, {"__builtins__": allowed_values}, allowed_values) return result
def validate_array(array): """ Builds a new array with valid values for the ShippingQuery constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from .peer import User data = UpdateType.validate_array(array) data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['invoice_payload'] = u(array.get('invoice_payload')) data['shipping_address'] = ShippingAddress.from_array( array.get('shipping_address')) return data
def __init__(self, source, type, field_name, data_hash, message): """ Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes. https://core.telegram.org/bots/api#passportelementerrordatafield Parameters: :param source: Error source, must be data :type source: str|unicode :param type: The section of the user's Telegram Passport which has the error, one of "personal_details", "passport", "driver_license", "identity_card", "internal_passport", "address" :type type: str|unicode :param field_name: Name of the data field which has the error :type field_name: str|unicode :param data_hash: Base64-encoded data hash :type data_hash: str|unicode :param message: Error message :type message: str|unicode Optional keyword parameters: """ super(PassportElementErrorDataField, self).__init__() assert_type_or_raise(source, unicode_type, parameter_name="source") self.source = source assert_type_or_raise(type, unicode_type, parameter_name="type") self.type = type assert_type_or_raise(field_name, unicode_type, parameter_name="field_name") self.field_name = field_name assert_type_or_raise(data_hash, unicode_type, parameter_name="data_hash") self.data_hash = data_hash assert_type_or_raise(message, unicode_type, parameter_name="message") self.message = message
def validate_array(array): """ Builds a new array with valid values for the PassportElementErrorFiles constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") data = PassportElementError.validate_array(array) data['source'] = u(array.get('source')) data['type'] = u(array.get('type')) data[ 'file_hashes'] = PassportElementErrorFiles._builtin_from_array_list( required_type=unicode_type, value=array.get('file_hashes'), list_level=1) data['message'] = u(array.get('message'))
def validate_array(array): """ Builds a new array with valid values for the StickerSet constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.media import Sticker data = Result.validate_array(array) data['name'] = u(array.get('name')) data['title'] = u(array.get('title')) data['is_animated'] = bool(array.get('is_animated')) data['contains_masks'] = bool(array.get('contains_masks')) data['stickers'] = Sticker.from_array_list(array.get('stickers'), list_level=1)
def from_array(array): """ Deserialize a new Chat from a given dictionary. :return: new Chat instance. :rtype: Chat """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from .media import ChatPhoto from .updates import Message data = {} data['id'] = int(array.get('id')) data['type'] = u(array.get('type')) data['title'] = u( array.get('title')) if array.get('title') is not None else None data['username'] = u(array.get('username')) if array.get( 'username') is not None else None data['first_name'] = u(array.get('first_name')) if array.get( 'first_name') is not None else None data['last_name'] = u(array.get('last_name')) if array.get( 'last_name') is not None else None data['all_members_are_administrators'] = bool( array.get('all_members_are_administrators')) if array.get( 'all_members_are_administrators') is not None else None data['photo'] = ChatPhoto.from_array( array.get('photo')) if array.get('photo') is not None else None data['description'] = u(array.get('description')) if array.get( 'description') is not None else None data['invite_link'] = u(array.get('invite_link')) if array.get( 'invite_link') is not None else None data['pinned_message'] = Message.from_array( array.get('pinned_message')) if array.get( 'pinned_message') is not None else None data['sticker_set_name'] = u( array.get('sticker_set_name')) if array.get( 'sticker_set_name') is not None else None data['can_set_sticker_set'] = bool( array.get('can_set_sticker_set')) if array.get( 'can_set_sticker_set') is not None else None data['_raw'] = array return Chat(**data)
def from_array(array): """ Deserialize a new EncryptedCredentials from a given dictionary. :return: new EncryptedCredentials instance. :rtype: EncryptedCredentials """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['data'] = u(array.get('data')) data['hash'] = u(array.get('hash')) data['secret'] = u(array.get('secret')) data['_raw'] = array return EncryptedCredentials(**data)
def validate_array(array): """ Builds a new array with valid values for the InlineQuery constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.media import Location from pytgbot.api_types.receivable.peer import User data = Result.validate_array(array) data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['query'] = u(array.get('query')) data['offset'] = u(array.get('offset')) data['location'] = Location.from_array(array.get( 'location')) if array.get('location') is not None else None
def from_array(array): """ Deserialize a new PassportFile from a given dictionary. :return: new PassportFile instance. :rtype: PassportFile """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['file_id'] = u(array.get('file_id')) data['file_size'] = int(array.get('file_size')) data['file_date'] = int(array.get('file_date')) data['_raw'] = array return PassportFile(**data)
def validate_array(array): """ Builds a new array with valid values for the SuccessfulPayment constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.payments import OrderInfo data = Result.validate_array(array) data['currency'] = u(array.get('currency')) data['total_amount'] = int(array.get('total_amount')) data['invoice_payload'] = u(array.get('invoice_payload')) data['telegram_payment_charge_id'] = u(array.get('telegram_payment_charge_id')) data['provider_payment_charge_id'] = u(array.get('provider_payment_charge_id')) data['shipping_option_id'] = u(array.get('shipping_option_id')) if array.get('shipping_option_id') is not None else None data['order_info'] = OrderInfo.from_array(array.get('order_info')) if array.get('order_info') is not None else None
def __init__(self, type, media, thumb=None, caption=None, parse_mode=None): """ Represents a general file to be sent. https://core.telegram.org/bots/api#inputmediadocument Parameters: :param type: Type of the result, must be document :type type: str|unicode :param media: File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>" to upload a new one using multipart/form-data under <file_attach_name> name. More info on Sending Files » :type media: str|unicode Optional keyword parameters: :param thumb: Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files » :type thumb: pytgbot.api_types.sendable.files.InputFile | str|unicode :param caption: Optional. Caption of the document to be sent, 0-1024 characters after entities parsing :type caption: str|unicode :param parse_mode: Optional. Mode for parsing entities in the document caption. See formatting options for more details. :type parse_mode: str|unicode """ super(InputMediaDocument, self).__init__() from .files import InputFile assert_type_or_raise(type, unicode_type, parameter_name="type") self.type = type assert_type_or_raise(media, unicode_type, parameter_name="media") self.media = media assert_type_or_raise(thumb, None, InputFile, unicode_type, parameter_name="thumb") self.thumb = thumb assert_type_or_raise(caption, None, unicode_type, parameter_name="caption") self.caption = caption assert_type_or_raise(parse_mode, None, unicode_type, parameter_name="parse_mode") self.parse_mode = parse_mode
def validate_array(array): """ Builds a new array with valid values for the StickerSet constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from .media import PhotoSize from .media import Sticker data = Result.validate_array(array) data['name'] = u(array.get('name')) data['title'] = u(array.get('title')) data['is_animated'] = bool(array.get('is_animated')) data['contains_masks'] = bool(array.get('contains_masks')) data['stickers'] = Sticker.from_array_list(array.get('stickers'), list_level=1) data['thumb'] = PhotoSize.from_array(array.get('thumb')) if array.get('thumb') is not None else None return data
def __init__( self, text: str, chat_id: Union[str, int, None] = None, reply_to_message_id: Union[int, None] = None, disable_notification: Union[bool, None] = False, parse_mode: str = self.DEFAULT, ): assert_type_or_raise(text, str, parameter_name='text') self.text = text MessageWithinChat.__init__(self, chat_id=chat_id, reply_to_message_id=reply_to_message_id, disable_notification=disable_notification) MessageMixinParseMode.__init__( self, parse_mode=parse_mode, )
def from_array(array): """ Deserialize a new ReplyKeyboardRemove from a given dictionary. :return: new ReplyKeyboardRemove instance. :rtype: ReplyKeyboardRemove """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['remove_keyboard'] = bool(array.get('remove_keyboard')) data['selective'] = bool(array.get('selective')) if array.get('selective') is not None else None instance = ReplyKeyboardRemove(**data) instance._raw = array return instance
def from_array(array): """ Deserialize a new InputMediaVideo from a given dictionary. :return: new InputMediaVideo instance. :rtype: InputMediaVideo """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.sendable.files import InputFile data = {} data['type'] = u(array.get('type')) data['media'] = u(array.get('media')) if array.get('thumb') is None: data['thumb'] = None elif isinstance(array.get('thumb'), InputFile): data['thumb'] = InputFile.from_array(array.get('thumb')) elif isinstance(array.get('thumb'), str): data['thumb'] = u(array.get('thumb')) else: raise TypeError( 'Unknown type, must be one of InputFile, str or None.') # end if data['caption'] = u( array.get('caption')) if array.get('caption') is not None else None data['parse_mode'] = u(array.get('parse_mode')) if array.get( 'parse_mode') is not None else None data['width'] = int( array.get('width')) if array.get('width') is not None else None data['height'] = int( array.get('height')) if array.get('height') is not None else None data['duration'] = int(array.get('duration')) if array.get( 'duration') is not None else None data['supports_streaming'] = bool( array.get('supports_streaming')) if array.get( 'supports_streaming') is not None else None instance = InputMediaVideo(**data) instance._raw = array return instance
def from_array(array): """ Deserialize a new LabeledPrice from a given dictionary. :return: new LabeledPrice instance. :rtype: LabeledPrice """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['label'] = u(array.get('label')) data['amount'] = int(array.get('amount')) instance = LabeledPrice(**data) instance._raw = array return instance
def from_array(array): """ Deserialize a new InlineKeyboardMarkup from a given dictionary. :return: new InlineKeyboardMarkup instance. :rtype: InlineKeyboardMarkup """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['inline_keyboard'] = InlineKeyboardButton.from_array_list( array.get('inline_keyboard'), list_level=2) instance = InlineKeyboardMarkup(**data) instance._raw = array return instance
def from_array(array): """ Deserialize a new ForceReply from a given dictionary. :return: new ForceReply instance. :rtype: ForceReply """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['force_reply'] = bool(array.get('force_reply')) data['selective'] = bool(array.get('selective')) if array.get('selective') is not None else None instance = ForceReply(**data) instance._raw = array return instance
def from_array(array): """ Deserialize a new MaskPosition from a given dictionary. :return: new MaskPosition instance. :rtype: MaskPosition """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['point'] = u(array.get('point')) data['x_shift'] = float(array.get('x_shift')) data['y_shift'] = float(array.get('y_shift')) data['scale'] = float(array.get('scale')) data['_raw'] = array return MaskPosition(**data)
def from_array(array): """ Deserialize a new PassportData from a given dictionary. :return: new PassportData instance. :rtype: PassportData """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['data'] = EncryptedPassportElement.from_array_list( array.get('data'), list_level=1) data['credentials'] = EncryptedCredentials.from_array( array.get('credentials')) data['_raw'] = array return PassportData(**data)
def __init__(self, id, from_peer, invoice_payload, shipping_address, _raw=None): """ This object contains information about an incoming shipping query. https://core.telegram.org/bots/api#shippingquery Parameters: :param id: Unique query identifier :type id: str|unicode :param from_peer: User who sent the query :type from_peer: pytgbot.api_types.receivable.peer.User :param invoice_payload: Bot specified invoice payload :type invoice_payload: str|unicode :param shipping_address: User specified shipping address :type shipping_address: pytgbot.api_types.receivable.payments.ShippingAddress Optional keyword parameters: :param _raw: Optional. Original data this object was generated from. Could be `None`. :type _raw: None | dict """ super(ShippingQuery, self).__init__() from pytgbot.api_types.receivable.payments import ShippingAddress from pytgbot.api_types.receivable.peer import User assert_type_or_raise(id, unicode_type, parameter_name="id") self.id = id assert_type_or_raise(from_peer, User, parameter_name="from_peer") self.from_peer = from_peer assert_type_or_raise(invoice_payload, unicode_type, parameter_name="invoice_payload") self.invoice_payload = invoice_payload assert_type_or_raise(shipping_address, ShippingAddress, parameter_name="shipping_address") self.shipping_address = shipping_address self._raw = _raw
def validate_array(array): """ Builds a new array with valid values for the PreCheckoutQuery constructor. :return: new array with valid values :rtype: dict """ assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.payments import OrderInfo from pytgbot.api_types.receivable.peer import User data = UpdateType.validate_array(array) data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['currency'] = u(array.get('currency')) data['total_amount'] = int(array.get('total_amount')) data['invoice_payload'] = u(array.get('invoice_payload')) data['shipping_option_id'] = u(array.get('shipping_option_id')) if array.get('shipping_option_id') is not None else None data['order_info'] = OrderInfo.from_array(array.get('order_info')) if array.get('order_info') is not None else None
def from_array(array): """ Deserialize a new GameHighScore from a given dictionary. :return: new GameHighScore instance. :rtype: GameHighScore """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.peer import User data = {} data['position'] = int(array.get('position')) data['user'] = User.from_array(array.get('user')) data['score'] = int(array.get('score')) data['_raw'] = array return GameHighScore(**data)